Navigation


Changeset 1121:ccbd1426e04a in freeDiameter for tests


Ignore:
Timestamp:
May 14, 2013, 4:27:28 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Improve testmesg_stress to measure impact of loaded dictionary

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/testmesg_stress.c

    r1119 r1121  
    3535
    3636#include "tests.h"
     37#include <dirent.h>
     38#include <libgen.h>
     39#include <dlfcn.h>
     40
     41#ifndef BUILD_DIR
     42#error "Missing BUILD_DIR information"
     43#endif /* BUILD_DIR */
     44
    3745
    3846/* The number of times each operation is repeated to measure the average operation time */
     
    4755}
    4856
    49 
     57struct ext_info {
     58        struct fd_list  chain;          /* link in the list */
     59        void            *handler;       /* object returned by dlopen() */
     60        int             (*init_cb)(int, int, char *);
     61        char            *ext_name;      /* points to the extension name, either inside depends, or basename(filename) */
     62        int             free_ext_name;  /* must be freed if it was malloc'd */
     63        const char      **depends;      /* names of the other extensions this one depends on (if provided) */
     64};
     65       
     66static void load_all_extensions(char * prefix)
     67{
     68        DIR *dir;
     69        struct dirent *dp;
     70        char fullname[512];
     71        int pathlen;
     72        struct fd_list all_extensions = FD_LIST_INITIALIZER(all_extensions);
     73        struct fd_list ext_with_depends = FD_LIST_INITIALIZER(ext_with_depends);
     74
     75        /* Find all extensions which have been compiled along the test */
     76        LOG_D("Loading %s*.fdx from: '%s'", BUILD_DIR "/extensions", prefix ?: "");
     77        CHECK( 0, (dir = opendir (BUILD_DIR "/extensions")) == NULL ? 1 : 0 );
     78        pathlen = snprintf(fullname, sizeof(fullname), BUILD_DIR "/extensions/");
     79       
     80        while ((dp = readdir (dir)) != NULL) {
     81                char * dot = strrchr(dp->d_name, '.');
     82                if (dot && ((!prefix) || !(strncmp(dp->d_name, prefix, strlen(prefix)))) && (!(strcmp(dot, ".fdx")))) {
     83                        /* We found a file with name dict_*.fdx, attempt to load it */
     84                        struct ext_info * new = malloc(sizeof(struct ext_info));
     85                        CHECK( 1, new ? 1:0);
     86                        fd_list_init(&new->chain, new);
     87                       
     88                        snprintf(fullname + pathlen, sizeof(fullname) - pathlen, "%s", dp->d_name);
     89                       
     90                        LOG_D("Extension: '%s'", dp->d_name);
     91                       
     92                        /* load */
     93                        new->handler = dlopen(fullname, RTLD_NOW | RTLD_GLOBAL);
     94                        if (!new->handler) {
     95                                TRACE_DEBUG(INFO, "Unable to load '%s': %s.", fullname, dlerror());
     96                        }
     97                        CHECK( 0, new->handler == NULL ? 1 : 0 );
     98                       
     99                        /* resolve entry */
     100                        new->init_cb = dlsym( new->handler, "fd_ext_init" );
     101                        if (!new->init_cb) {
     102                                TRACE_DEBUG(INFO, "No 'fd_ext_init' entry point in '%s': %s.", fullname, dlerror());
     103                        }
     104                        CHECK( 0, new->init_cb == NULL ? 1 : 0 );
     105                       
     106                        new->depends = dlsym( new->handler, "fd_ext_depends" );
     107                        if (new->depends) {
     108                                new->ext_name = (char *)new->depends[0];
     109                                new->free_ext_name = 0;
     110                                if ( new->depends[1] ) {
     111                                        fd_list_insert_before(&ext_with_depends, &new->chain);
     112                                } else {
     113                                        fd_list_insert_before(&all_extensions, &new->chain);
     114                                }
     115                        } else {
     116                                new->ext_name = strdup(basename(dp->d_name));
     117                                new->free_ext_name = 1;
     118                                fd_list_insert_before(&all_extensions, &new->chain);
     119                        }
     120                       
     121                }
     122        }
     123       
     124        /* Now, reorder the list by dependencies */
     125        {
     126                int count, prevcount = 0;
     127                struct fd_list * li;
     128                do {
     129                        count = 0;
     130                        for (li=ext_with_depends.next; li != &ext_with_depends; li=li->next) {
     131                                struct ext_info * e = li->o;
     132                                int d;
     133                                int satisfied=0;
     134                               
     135                                /* Can we satisfy all dependencies? */
     136                                for (d=1;  ;d++) {
     137                                        struct fd_list * eli;
     138                                        if (!e->depends[d]) {
     139                                                satisfied = 1;
     140                                                break;
     141                                        }
     142                                       
     143                                        /* can we find this dependency in the list? */
     144                                        for (eli=all_extensions.next; eli != &all_extensions; eli = eli->next) {
     145                                                struct ext_info * de = eli->o;
     146                                                if (!strcasecmp(de->ext_name, e->depends[d]))
     147                                                        break; /* this dependency is satisfied */
     148                                        }
     149                                       
     150                                        if (eli == &all_extensions) {
     151                                                satisfied = 0;
     152                                                break;
     153                                        }
     154                                }
     155                               
     156                                if (satisfied) {
     157                                        /* OK, we have all our dependencies in the list */
     158                                        li=li->prev;
     159                                        fd_list_unlink(&e->chain);
     160                                        fd_list_insert_before(&all_extensions, &e->chain);
     161                                } else {
     162                                        count++;
     163                                }
     164                        }
     165                       
     166                        if (prevcount && (prevcount == count)) {
     167                                LOG_E("Some extensions cannot have their dependencies satisfied, e.g.: %s", ((struct ext_info *)ext_with_depends.next->o)->ext_name);
     168                                CHECK(0, 1);
     169                        }
     170                        prevcount = count;
     171                       
     172                        if (FD_IS_LIST_EMPTY(&ext_with_depends))
     173                                break;
     174                } while (1);
     175        }
     176       
     177        /* Now, load all the extensions */
     178        {
     179                struct fd_list * li;
     180                for (li=all_extensions.next; li != &all_extensions; li=li->next) {
     181                        struct ext_info * e = li->o;
     182                        int ret = (*e->init_cb)( FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, NULL );
     183                        LOG_N("Initializing extension '%s': %s", e->ext_name, ret ? strerror(ret) : "Success");
     184                }
     185        }
     186       
     187        /* We should probably clean the list here ? */
     188}
    50189
    51190/* Main test routine */
     
    55194        unsigned char * buf = NULL;
    56195       
     196        int dictionaries_loaded = 0;
     197       
    57198        test_parameter = DEFAULT_NUMBER_OF_SAMPLES;
    58199       
    59200        /* First, initialize the daemon modules */
    60201        INIT_FD();
     202        CHECK( 0, fd_queues_init()  );
     203        CHECK( 0, fd_msg_init()  );
     204        CHECK( 0, fd_rtdisp_init()  );
     205       
    61206       
    62207        {
     
    379524       
    380525        /* We have our "buf" now, length is 344 -- cf. testmesg.c. */
    381        
     526redo:   
    382527        /* Test the throughput of the different functions function */
    383528        {
     
    531676                free(stress_array);
    532677        }
    533                
     678       
     679        if (!dictionaries_loaded) {
     680                load_all_extensions("dict_");
     681                dictionaries_loaded = 1;
     682                printf("Loaded all dictionary extensions, restarting...\n");
     683                goto redo;
     684        }
    534685       
    535686        /* That's all for the tests yet */
Note: See TracChangeset for help on using the changeset viewer.