Changeset c78c296 in rtems-libbsd


Ignore:
Timestamp:
Jul 15, 2016, 9:39:48 AM (4 years ago)
Author:
Christian Mauderer <Christian.Mauderer@…>
Branches:
4.11
Children:
87d0cda
Parents:
110dbd0
git-author:
Christian Mauderer <Christian.Mauderer@…> (07/15/16 09:39:48)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/03/16 12:13:18)
Message:

rtemsbsd: Add call to program with a data restore

This adds the rtems_bsd_program_call_main_width_data_restore function.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/include/machine/rtems-bsd-program.h

    r110dbd0 rc78c296  
    5454    int argc, char **argv);
    5555
     56int
     57rtems_bsd_program_call_main_with_data_restore(const char *name,
     58    int (*main)(int, char **), int argc, char **argv,
     59    const void *data_buf, const size_t data_size);
     60
    5661void
    5762rtems_bsd_program_exit(int exit_code) __dead2;
  • rtemsbsd/rtems/rtems-bsd-program.c

    r110dbd0 rc78c296  
    200200}
    201201
     202int
     203rtems_bsd_program_call_main_with_data_restore(const char *name,
     204    int (*main)(int, char **), int argc, char **argv,
     205    const void *data_buf, const size_t data_size)
     206{
     207        int exit_code = EXIT_FAILURE;
     208        void *savebuf;
     209
     210        savebuf = malloc(data_size, M_TEMP, 0);
     211        if(savebuf == NULL) {
     212                errno = ENOMEM;
     213                exit_code = EXIT_FAILURE;
     214        } else {
     215                memcpy(savebuf, data_buf, data_size);
     216                exit_code = rtems_bsd_program_call_main(name, main, argc,
     217                    argv);
     218                memcpy(data_buf, savebuf, data_size);
     219                free(savebuf, M_TEMP);
     220        }
     221
     222        return exit_code;
     223}
     224
    202225static struct mtx program_mtx;
    203226
  • testsuite/program01/test_main.c

    r110dbd0 rc78c296  
    171171}
    172172
     173#define OVERWRITE_CONTENT       "Some test pattern"
     174#define OVERWRITE_AFTER_RESTORE "xxxxxtestxxxxxxxx"
     175#define OVERWRITE_RESTORE_FIRST (5)
     176#define OVERWRITE_RESTORE_SIZE (4)
     177static const char overwrite_compare[] = OVERWRITE_AFTER_RESTORE;
     178static char overwrite_me[] = OVERWRITE_CONTENT;
     179
     180static int
     181overwrite_main(int argc, char **argv)
     182{
     183        size_t len = strlen(overwrite_me);
     184        memset(overwrite_me, 'x', len);
     185        assert(strcmp(overwrite_me, overwrite_compare) != 0);
     186        errno = 0;
     187        rtems_bsd_program_exit(1012);
     188}
     189
    173190static void
    174191test_bsd_program(void)
     
    197214        rtems_workspace_greedy_free(greedy);
    198215
     216        assert(rtems_resource_snapshot_check(&snapshot));
     217
    199218        errno = 0;
    200219        exit_code = rtems_bsd_program_call_main(prog_name, NULL, 1, invalid_argv);
    201220        assert(errno == EFAULT);
    202221        assert(exit_code == EXIT_FAILURE);
     222
     223        assert(rtems_resource_snapshot_check(&snapshot));
    203224
    204225        errno = EINVAL;
     
    208229        assert(strcmp(rtems_bsd_program_get_name(), "?") == 0);
    209230        assert(rtems_bsd_program_get_context() == NULL);
     231
     232        assert(rtems_resource_snapshot_check(&snapshot));
    210233
    211234        errno = EINVAL;
     
    218241
    219242        assert(rtems_resource_snapshot_check(&snapshot));
     243
     244        exit_code = rtems_bsd_program_call_main_with_data_restore(prog_name,
     245            overwrite_main, some_argc, some_argv,
     246            overwrite_me + OVERWRITE_RESTORE_FIRST, OVERWRITE_RESTORE_SIZE);
     247        assert(errno == 0);
     248        assert(exit_code == 1012);
     249        assert(strcmp(rtems_bsd_program_get_name(), "?") == 0);
     250        assert(rtems_bsd_program_get_context() == NULL);
     251        assert(strcmp(overwrite_me, overwrite_compare) == 0);
     252
     253        assert(rtems_resource_snapshot_check(&snapshot));
    220254}
    221255
Note: See TracChangeset for help on using the changeset viewer.