Advice on removing code redundancy

Saeed Ehteshamifar salpha.2004 at gmail.com
Wed Aug 19 14:26:13 UTC 2015


Hi,

Please take a look at following snippet:

testcase_executer.cpp:
1.  #include "___TC_abs_1.h"
2.
3.  void ___run_tc_abs_1 ()
4.  {
5.    rtems_id tc_task_id;
6.    rtems_name tc_task_name = rtems_build_name( 'T', 'C', ' ', ' ');
7.    rtems_task_create(
8.    tc_task_name, TC_TASK_PRIORITY, RTEMS_MINIMUM_STACK_SIZE,
9.      RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &tc_task_id);
10.
11.   rtems_task_start (tc_task_id, ___TC_abs_1, 0);
12.
13.   for (int i=0; i<TC_TIMEOUT_DIVISION_FACTOR; i++) {
14.     status = rtems_task_wake_after(RTEMS_MICROSECONDS_TO_TICKS(
15.       TC_TIMEOUT/TC_TIMEOUT_DIVISION_FACTOR));
16.     if (tc_finished)
17.       break;
18.   }
19. }
20.
21. rtems_task Init (rtems_task_argument)
22. {
23.   tc_finished = false;
24.   ___run_tc_wait_1 ();
25.   if (tc_finished)
26.     cout << "___TC_wait_1: " << "PASS" << endl;
27.   else
28.     cout << "___TC_wait_1: " << "RESTART" << endl;
29.   cout << endl;
30.
31.   cout << "finito!" << endl;
32.   exit (0);
33. }

It's going to be thousands of test cases, and I want to serially run each
test case in a task other than Init.
In the code above, I've marked symbols that are per each test case, with 3
leading underscores (___).
This is the basic duplication structure I've come up with. Since RTEMS
doesn't support dynamic linking, I'm going to duplicate lines 3 to 19
(___run_tc_abs_1) and 23 to 29 for each test case which leads to having a
very big source file for testcase_executer.cpp.
Is there any better solution that avoids code redundancy that I'm not aware
of? Do you have advices on how to change this structure to minimize code
redundancy? Any help is much appreciated.
Note: ___TC_abs_1 is already defined in a separate CPP file.

Thanks for your time.

Kind Regards,
SAeeD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20150819/ec1c4f3c/attachment.html>


More information about the users mailing list