HelenOS sources
This source file includes following definitions.
- test_dlsym
- test_dlfcn_dl_get_constant
- test_dlfcn_dl_get_constant_via_call
- test_dlfcn_dl_get_private_var
- test_dlfcn_dl_get_private_uvar
- test_dlfcn_dl_get_public_var
- test_dlfcn_dl_get_public_uvar
- test_dlfcn_read_public_var
- test_dlfcn_read_public_uvar
- test_dlfcn_dl_get_private_fib_var
- test_dlfcn_dl_get_private_fib_uvar
- test_dlfcn_dl_get_public_fib_var
- test_dlfcn_dl_get_public_fib_uvar
- test_dlfcn_read_public_fib_var
- test_dlfcn_read_public_fib_uvar
- test_public_ptr_var
- test_lnk_dl_get_constant
- test_lnk_dl_get_constant_via_call
- test_lnk_dl_get_private_var
- test_lnk_dl_get_private_uvar
- test_lnk_dl_get_public_var
- test_lnk_dl_get_public_uvar
- test_lnk_read_public_var
- test_lnk_read_public_uvar
- test_lnk_dl_get_private_fib_var
- test_lnk_dl_get_private_fib_uvar
- test_lnk_dl_get_public_fib_var
- test_lnk_dl_get_public_fib_uvar
- test_lnk_read_public_fib_var
- test_lnk_read_public_fib_uvar
- test_dlfcn
- test_lnk
- print_syntax
- main
#include <dlfcn.h>
#include <libdltest.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <str.h>
static void *handle;
static bool no_dlfcn = false;
static bool test_dlsym(void)
{
int (*p_dl_get_constant)(void);
printf("dlsym()... ");
p_dl_get_constant = dlsym(handle, "dl_get_constant");
if (p_dl_get_constant == NULL) {
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_constant(void)
{
int (*p_dl_get_constant)(void);
int val;
printf("Call dlsym/dl_get_constant...\n");
p_dl_get_constant = dlsym(handle, "dl_get_constant");
if (p_dl_get_constant == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_constant();
printf("Got %d, expected %d... ", val, dl_constant);
if (val != dl_constant) {
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_constant_via_call(void)
{
int (*p_dl_get_constant)(void);
int val;
printf("Call dlsym/dl_get_constant_via_call...\n");
p_dl_get_constant = dlsym(handle, "dl_get_constant_via_call");
if (p_dl_get_constant == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_constant();
printf("Got %d, expected %d... ", val, dl_constant);
if (val != dl_constant) {
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_private_var(void)
{
int (*p_dl_get_private_var)(void);
int *(*p_dl_get_private_var_addr)(void);
int val;
printf("Call dlsym/dl_get_private_var...\n");
p_dl_get_private_var = dlsym(handle, "dl_get_private_var");
if (p_dl_get_private_var == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_private_var_addr = dlsym(handle, "dl_get_private_var_addr");
if (p_dl_get_private_var_addr == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_private_var();
printf("Got %d, expected %d... ", val, dl_private_var_val);
if (val != dl_private_var_val) {
printf("dl_get_private_var_addr -> %p\n",
p_dl_get_private_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_private_uvar(void)
{
int (*p_dl_get_private_uvar)(void);
int *(*p_dl_get_private_uvar_addr)(void);
int val;
printf("Call dlsym/dl_get_private_uvar...\n");
p_dl_get_private_uvar = dlsym(handle, "dl_get_private_uvar");
if (p_dl_get_private_uvar == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_private_uvar_addr = dlsym(handle, "dl_get_private_uvar_addr");
if (p_dl_get_private_uvar_addr == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_private_uvar();
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("dl_get_private_uvar_addr -> %p\n",
p_dl_get_private_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_public_var(void)
{
int (*p_dl_get_public_var)(void);
int *(*p_dl_get_public_var_addr)(void);
int val;
printf("Call dlsym/dl_get_public_var...\n");
p_dl_get_public_var = dlsym(handle, "dl_get_public_var");
if (p_dl_get_public_var == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_public_var_addr = dlsym(handle, "dl_get_public_var_addr");
if (p_dl_get_public_var_addr == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_public_var();
printf("Got %d, expected %d... ", val, dl_public_var_val);
if (val != dl_public_var_val) {
printf("dl_get_public_var_addr -> %p\n",
p_dl_get_public_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_public_uvar(void)
{
int (*p_dl_get_public_uvar)(void);
int *(*p_dl_get_public_uvar_addr)(void);
int val;
printf("Call dlsym/dl_get_public_uvar...\n");
p_dl_get_public_uvar = dlsym(handle, "dl_get_public_uvar");
if (p_dl_get_public_uvar == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_public_uvar_addr = dlsym(handle, "dl_get_public_uvar_addr");
if (p_dl_get_public_uvar_addr == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_public_uvar();
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("dl_get_public_uvar_addr -> %p\n",
p_dl_get_public_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_read_public_var(void)
{
int *p_dl_public_var;
int *(*p_dl_get_public_var_addr)(void);
int val;
printf("Read dlsym/dl_public_var...\n");
p_dl_public_var = dlsym(handle, "dl_public_var");
if (p_dl_public_var == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_public_var_addr = dlsym(handle, "dl_get_public_var_addr");
if (p_dl_get_public_var_addr == NULL) {
printf("FAILED\n");
return false;
}
val = *p_dl_public_var;
printf("Got %d, expected %d... ", val, dl_public_var_val);
if (val != dl_public_var_val) {
printf("&dl_public_var = %p, "
"dl_get_public_var_addr -> %p\n",
p_dl_public_var, p_dl_get_public_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_read_public_uvar(void)
{
int *p_dl_public_uvar;
int *(*p_dl_get_public_uvar_addr)(void);
int val;
printf("Read dlsym/dl_public_uvar...\n");
p_dl_public_uvar = dlsym(handle, "dl_public_uvar");
if (p_dl_public_uvar == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_public_uvar_addr = dlsym(handle, "dl_get_public_uvar_addr");
if (p_dl_get_public_uvar_addr == NULL) {
printf("FAILED\n");
return false;
}
val = *p_dl_public_uvar;
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("&dl_public_uvar = %p, "
"dl_get_public_uvar_addr -> %p\n",
p_dl_public_uvar, p_dl_get_public_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
#ifndef STATIC_EXE
static bool test_dlfcn_dl_get_private_fib_var(void)
{
int (*p_dl_get_private_fib_var)(void);
int *(*p_dl_get_private_fib_var_addr)(void);
int val;
printf("Call dlsym/dl_get_private_fib_var...\n");
p_dl_get_private_fib_var = dlsym(handle, "dl_get_private_fib_var");
if (p_dl_get_private_fib_var == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_private_fib_var_addr = dlsym(handle, "dl_get_private_fib_var_addr");
if (p_dl_get_private_fib_var_addr == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_private_fib_var();
printf("Got %d, expected %d... ", val, dl_private_fib_var_val);
if (val != dl_private_fib_var_val) {
printf("dl_get_private_fib_var_addr -> %p\n",
p_dl_get_private_fib_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_private_fib_uvar(void)
{
int (*p_dl_get_private_fib_uvar)(void);
int *(*p_dl_get_private_fib_uvar_addr)(void);
int val;
printf("Call dlsym/dl_get_private_fib_uvar...\n");
p_dl_get_private_fib_uvar = dlsym(handle, "dl_get_private_fib_uvar");
if (p_dl_get_private_fib_uvar == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_private_fib_uvar_addr = dlsym(handle, "dl_get_private_fib_uvar_addr");
if (p_dl_get_private_fib_uvar_addr == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_private_fib_uvar();
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("dl_get_private_fib_uvar_addr -> %p\n",
p_dl_get_private_fib_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_public_fib_var(void)
{
int (*p_dl_get_public_fib_var)(void);
int *(*p_dl_get_public_fib_var_addr)(void);
int val;
printf("Call dlsym/dl_get_public_fib_var...\n");
p_dl_get_public_fib_var = dlsym(handle, "dl_get_public_fib_var");
if (p_dl_get_public_fib_var == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_public_fib_var_addr = dlsym(handle, "dl_get_public_fib_var_addr");
if (p_dl_get_public_fib_var_addr == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_public_fib_var();
printf("Got %d, expected %d... ", val, dl_public_fib_var_val);
if (val != dl_public_fib_var_val) {
printf("dl_get_public_fib_var_addr -> %p\n",
p_dl_get_public_fib_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_dl_get_public_fib_uvar(void)
{
int (*p_dl_get_public_fib_uvar)(void);
int *(*p_dl_get_public_fib_uvar_addr)(void);
int val;
printf("Call dlsym/dl_get_public_fib_uvar...\n");
p_dl_get_public_fib_uvar = dlsym(handle, "dl_get_public_fib_uvar");
if (p_dl_get_public_fib_uvar == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_public_fib_uvar_addr = dlsym(handle, "dl_get_public_fib_uvar_addr");
if (p_dl_get_public_fib_uvar_addr == NULL) {
printf("FAILED\n");
return false;
}
val = p_dl_get_public_fib_uvar();
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("dl_get_public_fib_uvar_addr -> %p\n",
p_dl_get_public_fib_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_read_public_fib_var(void)
{
int *p_dl_public_fib_var;
int *(*p_dl_get_public_fib_var_addr)(void);
int val;
printf("Read dlsym/dl_public_fib_var...\n");
p_dl_public_fib_var = dlsym(handle, "dl_public_fib_var");
if (p_dl_public_fib_var == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_public_fib_var_addr = dlsym(handle, "dl_get_public_fib_var_addr");
if (p_dl_get_public_fib_var_addr == NULL) {
printf("FAILED\n");
return false;
}
val = *p_dl_public_fib_var;
printf("Got %d, expected %d... ", val, dl_public_fib_var_val);
if (val != dl_public_fib_var_val) {
printf("&dl_public_fib_var = %p, "
"dl_get_public_fib_var_addr -> %p\n",
p_dl_public_fib_var, p_dl_get_public_fib_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_dlfcn_read_public_fib_uvar(void)
{
int *p_dl_public_fib_uvar;
int *(*p_dl_get_public_fib_uvar_addr)(void);
int val;
printf("Read dlsym/dl_public_fib_uvar...\n");
p_dl_public_fib_uvar = dlsym(handle, "dl_public_fib_uvar");
if (p_dl_public_fib_uvar == NULL) {
printf("FAILED\n");
return false;
}
p_dl_get_public_fib_uvar_addr = dlsym(handle, "dl_get_public_fib_uvar_addr");
if (p_dl_get_public_fib_uvar_addr == NULL) {
printf("FAILED\n");
return false;
}
val = *p_dl_public_fib_uvar;
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("&dl_public_fib_uvar = %p, "
"dl_get_public_fib_uvar_addr -> %p\n",
p_dl_public_fib_uvar, p_dl_get_public_fib_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
#endif
#ifdef DLTEST_LINKED
static bool test_public_ptr_var(void)
{
int *ptr;
printf("Read dl_public_ptr_var directly...\n");
ptr = dl_public_ptr_var;
if (ptr != &dl_public_var) {
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_constant(void)
{
int val;
printf("Call linked dl_get_constant...\n");
val = dl_get_constant();
printf("Got %d, expected %d... ", val, dl_constant);
if (val != dl_constant) {
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_constant_via_call(void)
{
int val;
printf("Call linked dl_get_constant_via_call...\n");
val = dl_get_constant_via_call();
printf("Got %d, expected %d... ", val, dl_constant);
if (val != dl_constant) {
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_private_var(void)
{
int val;
printf("Call linked dl_get_private_var...\n");
val = dl_get_private_var();
printf("Got %d, expected %d... ", val, dl_private_var_val);
if (val != dl_private_var_val) {
printf("dl_get_private_var_addr -> %p\n",
dl_get_private_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_private_uvar(void)
{
int val;
printf("Call linked dl_get_private_uvar...\n");
val = dl_get_private_uvar();
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("dl_get_private_uvar_addr -> %p\n",
dl_get_private_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_public_var(void)
{
int val;
printf("Call linked dl_get_public_var...\n");
val = dl_get_public_var();
printf("Got %d, expected %d... ", val, dl_public_var_val);
if (val != dl_public_var_val) {
printf("dl_get_public_var_addr -> %p\n",
dl_get_public_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_public_uvar(void)
{
int val;
printf("Call linked dl_get_public_uvar...\n");
val = dl_get_public_uvar();
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("dl_get_public_uvar_addr -> %p\n",
dl_get_public_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_read_public_var(void)
{
int val;
printf("Read linked dl_public_var...\n");
val = dl_public_var;
printf("Got %d, expected %d... ", val, dl_public_var_val);
if (val != dl_public_var_val) {
printf("&dl_public_var = %p, dl_get_public_var_addr -> %p\n",
&dl_public_var, dl_get_public_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_read_public_uvar(void)
{
int val;
printf("Read linked dl_public_uvar...\n");
val = dl_public_uvar;
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("&dl_public_uvar = %p, dl_get_public_uvar_addr -> %p\n",
&dl_public_uvar, dl_get_public_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_private_fib_var(void)
{
int val;
printf("Call linked dl_get_private_fib_var...\n");
val = dl_get_private_fib_var();
printf("Got %d, expected %d... ", val, dl_private_fib_var_val);
if (val != dl_private_fib_var_val) {
printf("dl_get_private_fib_var_addr -> %p\n",
dl_get_private_fib_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_private_fib_uvar(void)
{
int val;
printf("Call linked dl_get_private_fib_uvar...\n");
val = dl_get_private_fib_uvar();
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("dl_get_private_fib_uvar_addr -> %p\n",
dl_get_private_fib_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_public_fib_var(void)
{
int val;
printf("Call linked dl_get_public_fib_var...\n");
val = dl_get_public_fib_var();
printf("Got %d, expected %d... ", val, dl_public_fib_var_val);
if (val != dl_public_fib_var_val) {
printf("dl_get_public_fib_var_addr -> %p\n",
dl_get_public_fib_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_dl_get_public_fib_uvar(void)
{
int val;
printf("Call linked dl_get_public_fib_uvar...\n");
val = dl_get_public_fib_uvar();
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("dl_get_public_fib_uvar_addr -> %p\n",
dl_get_public_fib_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_read_public_fib_var(void)
{
int val;
printf("Read linked dl_public_fib_var...\n");
val = dl_public_fib_var;
printf("Got %d, expected %d... ", val, dl_public_fib_var_val);
if (val != dl_public_fib_var_val) {
printf("&dl_public_fib_var = %p, "
"dl_get_public_fib_var_addr -> %p\n",
&dl_public_fib_var, dl_get_public_fib_var_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
static bool test_lnk_read_public_fib_uvar(void)
{
int val;
printf("Read linked dl_public_fib_uvar...\n");
val = dl_public_fib_uvar;
printf("Got %d, expected %d... ", val, 0);
if (val != 0) {
printf("&dl_public_fib_uvar = %p, "
"dl_get_public_fib_uvar_addr -> %p\n",
&dl_public_fib_uvar, dl_get_public_fib_uvar_addr());
printf("FAILED\n");
return false;
}
printf("Passed\n");
return true;
}
#endif
static int test_dlfcn(void)
{
printf("dlopen()... ");
handle = dlopen("libdltest.so.0", 0);
if (handle == NULL) {
printf("FAILED\n");
return 1;
}
printf("Passed\n");
if (!test_dlsym())
return 1;
if (!test_dlfcn_dl_get_constant())
return 1;
if (!test_dlfcn_dl_get_constant_via_call())
return 1;
if (!test_dlfcn_dl_get_private_var())
return 1;
if (!test_dlfcn_dl_get_private_uvar())
return 1;
if (!test_dlfcn_dl_get_public_var())
return 1;
if (!test_dlfcn_dl_get_public_uvar())
return 1;
if (!test_dlfcn_read_public_var())
return 1;
if (!test_dlfcn_read_public_uvar())
return 1;
#ifndef STATIC_EXE
if (!test_dlfcn_dl_get_private_fib_var())
return 1;
if (!test_dlfcn_dl_get_private_fib_uvar())
return 1;
if (!test_dlfcn_dl_get_public_fib_var())
return 1;
if (!test_dlfcn_dl_get_public_fib_uvar())
return 1;
if (!test_dlfcn_read_public_fib_var())
return 1;
if (!test_dlfcn_read_public_fib_uvar())
return 1;
#endif
#if 0
printf("dlclose()... ");
dlclose(handle);
printf("Passed\n");
#endif
return 0;
}
#ifdef DLTEST_LINKED
static int test_lnk(void)
{
if (!test_lnk_dl_get_constant())
return 1;
if (!test_lnk_dl_get_constant_via_call())
return 1;
if (!test_lnk_dl_get_private_var())
return 1;
if (!test_lnk_dl_get_private_uvar())
return 1;
if (!test_lnk_dl_get_public_var())
return 1;
if (!test_lnk_dl_get_public_uvar())
return 1;
if (!test_lnk_read_public_var())
return 1;
if (!test_lnk_read_public_uvar())
return 1;
if (!test_public_ptr_var())
return 1;
if (!test_lnk_dl_get_private_fib_var())
return 1;
if (!test_lnk_dl_get_private_fib_uvar())
return 1;
if (!test_lnk_dl_get_public_fib_var())
return 1;
if (!test_lnk_dl_get_public_fib_uvar())
return 1;
if (!test_lnk_read_public_fib_var())
return 1;
if (!test_lnk_read_public_fib_uvar())
return 1;
return 0;
}
#endif
static void print_syntax(void)
{
fprintf(stderr, "syntax: dltest [-n]\n");
fprintf(stderr, "\t-n Do not run dlfcn tests\n");
}
int main(int argc, char *argv[])
{
printf("Dynamic linking test\n");
if (argc > 1) {
if (argc > 2) {
print_syntax();
return 1;
}
if (str_cmp(argv[1], "-n") == 0) {
no_dlfcn = true;
} else {
print_syntax();
return 1;
}
}
if (!no_dlfcn) {
if (test_dlfcn() != 0)
return 1;
}
#ifdef DLTEST_LINKED
if (test_lnk() != 0)
return 1;
#endif
printf("All passed.\n");
return 0;
}
HelenOS homepage, sources at GitHub