Changeset 8e3bc063 in mainline


Ignore:
Timestamp:
2019-01-14T14:38:18Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1c3c287
Parents:
e0e5e6f5
git-author:
Jiri Svoboda <jiri@…> (2018-01-13 18:38:00)
git-committer:
Jiri Svoboda <jiri@…> (2019-01-14 14:38:18)
Message:

dltest needs test that calls a function

During bringup of dynamic linking on a platform it is difficult to test
dynamic function calls (via PLT) if the binaries (including dltest)
are statically linked. We can do that by adding a function to libdltest
that calls another function. Since we don't use -Bsymbolic, the call
will be made via PLT.

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/dltest/dltest.c

    re0e5e6f5 r8e3bc063  
    9191}
    9292
     93/** Test calling function that calls a function that returns a constant */
     94static bool test_dlfcn_dl_get_constant_via_call(void)
     95{
     96        int (*p_dl_get_constant)(void);
     97        int val;
     98
     99        printf("Call dlsym/dl_get_constant_via_call...\n");
     100
     101        p_dl_get_constant = dlsym(handle, "dl_get_constant_via_call");
     102        if (p_dl_get_constant == NULL) {
     103                printf("FAILED\n");
     104                return false;
     105        }
     106
     107        val = p_dl_get_constant();
     108
     109        printf("Got %d, expected %d... ", val, dl_constant);
     110        if (val != dl_constant) {
     111                printf("FAILED\n");
     112                return false;
     113        }
     114
     115        printf("Passed\n");
     116        return true;
     117}
     118
    93119/** Test calling a function that returns contents of a private initialized
    94120 * variable.
     
    564590}
    565591
     592/** Test directly calling function that calls a function that returns a constant */
     593static bool test_lnk_dl_get_constant_via_call(void)
     594{
     595        int val;
     596
     597        printf("Call linked dl_get_constant_via_call...\n");
     598
     599        val = dl_get_constant_via_call();
     600
     601        printf("Got %d, expected %d... ", val, dl_constant);
     602        if (val != dl_constant) {
     603                printf("FAILED\n");
     604                return false;
     605        }
     606
     607        printf("Passed\n");
     608        return true;
     609}
     610
    566611/** Test dircetly calling a function that returns contents of a private
    567612 * initialized variable.
     
    853898                return 1;
    854899
     900        if (!test_dlfcn_dl_get_constant_via_call())
     901                return 1;
     902
    855903        if (!test_dlfcn_dl_get_private_var())
    856904                return 1;
     
    905953{
    906954        if (!test_lnk_dl_get_constant())
     955                return 1;
     956
     957        if (!test_lnk_dl_get_constant_via_call())
    907958                return 1;
    908959
  • uspace/lib/dltest/dltest.c

    re0e5e6f5 r8e3bc063  
    6060{
    6161        return dl_constant;
     62}
     63
     64/** Return constant value by calling another function.
     65 *
     66 * This can be used to test dynamically linked call (via PLT) even in case
     67 * binaries are statically linked.
     68 */
     69int dl_get_constant_via_call(void)
     70{
     71        return dl_get_constant();
    6272}
    6373
  • uspace/lib/dltest/libdltest.h

    re0e5e6f5 r8e3bc063  
    4747
    4848extern int dl_get_constant(void);
     49extern int dl_get_constant_via_call(void);
    4950extern int dl_get_private_var(void);
    5051extern int *dl_get_private_var_addr(void);
Note: See TracChangeset for help on using the changeset viewer.