IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 560


Ignore:
Timestamp:
May 1, 2004, 1:04:35 PM (22 years ago)
Author:
gusciora
Message:

This is a fairly large checkin. I had been sitting on a lot of test code
that was not quite in sync with the current test harness. I modified it
somewhat so it mostly works with the test harness, though there are still
problems with the printFooter() function not having a status for "status
unknown". Also, the runTest is not correctly parsing my date strings in
psLogMsg calls. Also, I added an individual entry for each test in the
Makefile in the test directory. I did this because the generic rules were
failing, and I did not want to break the tests for those people who were
successfully using the generic rules.

Location:
trunk/psLib
Files:
30 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psLogMsg.c

    r500 r560  
    261261        head_ptr += strlen(head_ptr);
    262262    }
     263
    263264    if (head_ptr > head) {
    264265        *head_ptr++ = '|';
     
    269270    case PS_LOG_TO_STDOUT:
    270271        puts(head);
    271         vprintf(fmt, ap);
    272         if (fmt[strlen(fmt) - 1] != '\n') {
     272        if (log_msg) {
     273            vprintf(fmt, ap);
     274            if (fmt[strlen(fmt) - 1] != '\n') {
     275                putc('\n', stdout);
     276            }
     277        } else {
    273278            putc('\n', stdout);
    274279        }
     
    277282    case PS_LOG_TO_STDERR:
    278283        fputs(head, stderr);
    279         vfprintf(stderr, fmt, ap);
    280         if (fmt[strlen(fmt) - 1] != '\n') {
     284        if (log_msg) {
     285            vfprintf(stderr, fmt, ap);
     286            if (fmt[strlen(fmt) - 1] != '\n') {
     287                putc('\n', stderr);
     288            }
     289        } else {
    281290            putc('\n', stderr);
    282291        }
  • trunk/psLib/src/sys/psTrace.c

    r559 r560  
    11/*****************************************************************************
    2     A simple implementation of a tracing facility for Pan-STARRS
    3  
    4     Tracing is controlled on a per "component" basis, where a "component" is
    5     a name of the form aaa.bbb.ccc where aaa is the most significant part.
    6     For example, the utilities library might be called "utils", the
    7     doubly-linked list "utils.dlist", and the code to destroy a list
    8     "utils.dlist.del".
     2    A simple implementation of a tracing facility for Pan-STARRS.  Tracing
     3    is controlled on a per "component" basis, where a "component" is a name
     4    of the form aaa.bbb.ccc where aaa is the most significant part.
    95 
    106    NOTES:
    11  In the SRD, higher trace levels correspond to a numerically lower
    12  trace value in the code.  This is a bit confusing.
     7 In the SRD, higher trace levels correspond to a numerically lower trace
     8 value in the code.  This is a bit confusing.  For example, a high-level
     9 message might be something like "Begin Processing".  The module programmer
     10 might give that a numerically low trace level, such as 1, so then any
     11 non-zero trace level in that code component will display thatmessage.
    1312 
    1413 We build a tree of trace components.  Every node in the tree has a
    1514 depth, which is it's distance from the root.  However, this is not
    1615 not the same thing as a node's "level", which corresponds to the
    17  trace level of that node.  I should probably rename some variables.
    18  
    19  This code is obduscated by the fact that component names are of the form
     16 trace level of that node.
     17 
     18 This code is obfuscated by the fact that component names are of the form
    2019 ".a.b.c.d" where "." is always the root of the tree, and for tree that have
    2120 a depth of 3 or higher (including the root ".") the "."  character is also
     
    2423 while the last three dots merely act as separators between the node names
    2524 "b", "c", and "d".
     25 
     26 I added a function psTraceFree() which frees all nodes in the trace component
     27 tree.  Previously, there had been no function in the API which accomplished
     28 this purpose.
    2629 *****************************************************************************/
    2730#include <stdlib.h>
     
    2932#include <string.h>
    3033#include <stdarg.h>
    31 /* #include "psLib.h" */
     34/* #include "pslib.h" */
    3235#include "psMemory.h"
    3336#include "psTrace.h"
    3437#include "psString.h"
    35 
    36 #define CACHE_NAME_LEN 50
    37 #define NO_CACHE "\a"                     // no name is cached
    38 /*****************************************************************************
    39     A component is a string of the form aaa.bbb.ccc, and may itself contain
    40     further subcomponents.  The Component structure doesn't in fact contain
    41     it's full name, but only the last part.
    42  *****************************************************************************/
    43 typedef struct Component
    44 {
    45     const char *name;                     // last part of name of component
    46     int level;                            // trace level for this component
    47     int dimen;                            // dimension of subcomponents
    48     int n;                                // number of subcomponents
    49     struct Component **subcomp;           // next level of subcomponents
    50 }
    51 Component;
     38#include "psError.h"
    5239
    5340static Component *croot = NULL;           // The root of the trace component
    54 // tree.
    55 
    56 // NOTE: the next tree globals exist for optimization purposes only.
    57 // Consider removing them.
    58 static int highest_level = 0;             // Highest level requested.  Defining
    59 // this variable allows us to reduce component-tree searches that tell
    60 // us if a message should be printed.
    61 static char cachedName[CACHE_NAME_LEN + 1] = NO_CACHE;
    62 // last name looked up
    63 static int cachedLevel;                   // level of last looked up name
    64 
    65 
    6641/*****************************************************************************
    6742    componentAlloc(): allocate memory for a new node, and initialize members.
     
    7045                          int level)
    7146{
    72     //printf("Calling componentAlloc(%s, %d)\n", name, level);
    7347    Component *comp = psAlloc(sizeof(Component));
    7448    comp->name = psStringCopy(name);
    7549    comp->level = level;
    76     comp->dimen = comp->n = 0;
     50    comp->n = 0;
    7751    comp->subcomp = NULL;
    7852    return comp;
     
    10882{
    10983    if (croot == NULL) {
    110         croot = componentAlloc(".", UNKNOWN_TRACE_LEVEL);
    111     }
    112 }
    113 
    114 
    115 /*****************************************************************************
    116     Free the trace tree information
    117  *****************************************************************************/
    118 void psTraceReset(void)
     84        croot = componentAlloc(".", DEFAULT_TRACE_LEVEL);
     85    }
     86}
     87
     88
     89/*****************************************************************************
     90    Set all trace levels to zero.
     91 *****************************************************************************/
     92void p_psTraceReset(Component *currentNode)
     93{
     94    int i = 0;
     95
     96    if (NULL == currentNode) {
     97        return;
     98    }
     99
     100    currentNode->level = 0;
     101    for (i=0;i<currentNode->n;i++) {
     102        if (NULL == currentNode->subcomp[i]) {
     103            psError(__func__,
     104                    "Sub-component %d of node %s in the trace tree is NULL.\n",
     105                    i, currentNode->name);
     106        } else {
     107            p_psTraceReset(currentNode->subcomp[i]);
     108        }
     109    }
     110    return;
     111}
     112
     113void psTraceReset()
     114{
     115    p_psTraceReset(croot);
     116}
     117
     118
     119void psTraceFree()
    119120{
    120121    componentFree(croot);
    121     croot = NULL;
    122122}
    123123
     
    140140    int        nodeExists = 0;
    141141
    142     // printf("Calling componentAdd(%s, %d)\n", addNodeName, level);
    143142    // Is this the root node?  If so, simply set level and return.
    144143    if (strcmp(".", addNodeName) == 0) {
     
    185184
    186185/*****************************************************************************
    187     setHighestLevel(): traverse the component tree recursively.  For each
    188  node encountered, if it's trace level is higher than the global
    189  variable highest_level, then set highest_level to that nodes trace
    190  level.
    191     Input:
    192  comp
    193     Output:
    194  none
    195     Returns:
    196  NULL
    197  *****************************************************************************/
    198 static void setHighestLevel(const Component *comp)
    199 {
    200     int i = 0;
    201 
    202     if (comp == NULL) {
    203         printf("ERROR: setHighestLevel(NULL)\n");
    204         exit(1);
    205     }
    206 
    207     // If this nodes trace level is the max so far, save it in highest_level
    208     if (comp->level > highest_level) {
    209         highest_level = comp->level;
    210     }
    211 
    212     // Do the same for all children nodes.
    213     for (i = 0; i < comp->n; i++) {
    214         setHighestLevel(comp->subcomp[i]);
    215     }
    216 }
    217 
    218 
    219 /*****************************************************************************
    220186    psSetTraceLevel(): add the component named "comp" to the component tree,
    221187 if it is not already there, and set it's trace level to "level".
     
    236202    }
    237203
    238     //printf("Calling psSetTraceLevel(%s, %d)\n", comp, level);
    239     // invalidate cache
    240     strncpy(cachedName, NO_CACHE, CACHE_NAME_LEN);
    241 
    242204    // Add the new component to the component tree.
    243205    componentAdd(comp, level);
    244206
    245     // Save this search info in our depth-one cache.
    246     if (level > highest_level) {
    247         highest_level = level;
    248     } else {
    249         highest_level = UNKNOWN_TRACE_LEVEL;
    250         setHighestLevel(croot);
    251     }
    252 
    253207    // return 0 on success.
    254     //printf("Called psSetTraceLevel(%s, %d)\n", comp, level);
    255208    return 0;
    256209}
     
    279232    int        i = 0;
    280233
     234    if (NULL == currentNode) {
     235        return(UNKNOWN_TRACE_LEVEL);
     236    }
     237
    281238    if (strcmp(".", aname) == 0) {
    282239        return(croot->level);
     
    292249        firstComponent = strsep(&pname, ".");
    293250        for (i = 0; i < currentNode->n; i++) {
     251            if (NULL == currentNode->subcomp[i]) {
     252                psError(__func__,
     253                        "Sub-component %d of node %s in trace tree is NULL.\n",
     254                        i, currentNode->name);
     255            }
     256
    294257            if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
    295258                currentNode = currentNode->subcomp[i];
     
    318281int psGetTraceLevel(const char *name)
    319282{
    320     int level = -1;
    321 
    322     //printf("Calling psGetTraceLevel(%s)\n", name);
    323     // If the root component tree does not exist, then initialize it.
    324283    if (croot == NULL) {
    325         initTrace();
    326     }
    327 
    328     // Before we traverse the component tree, check if we just searched for
    329     // this name, and if so, return that level.
    330     if (strcmp(name, cachedName) == 0) {
    331         return cachedLevel;
     284        return(UNKNOWN_TRACE_LEVEL);
    332285    }
    333286
    334287    // Search the component root tree, determine the trace level.
    335     level = doGetTraceLevel(name);
    336 
    337     // Save this search info in our depth-one cache.
    338     strncpy(cachedName, name, CACHE_NAME_LEN);
    339     cachedLevel = level;
    340 
    341     //printf("Called psGetTraceLevel(%s) (level was %d)\n", name, level);
    342     return level;
     288    return(doGetTraceLevel(name));
    343289}
    344290
     
    392338void psPrintTraceLevels(void)
    393339{
    394     // If the root component tree does not exist, then initialize it.
    395340    if (croot == NULL) {
    396         initTrace();
     341        return;
    397342    }
    398343
     
    423368    int i = 0;
    424369
    425     // We first check if the level of this message is less than the highest
    426     // level in the tree.  If so, we don't go any further.  If not, we need
    427     // to determine the trace level of comp, and then display the message if
    428     // the comp's trace level is high enough.
    429 
    430     if ((level <= highest_level) &&
    431             (level <= psGetTraceLevel(comp))) {
     370    if (NULL == comp) {
     371        psError(__func__,
     372                "p_psTrace() called on a NULL trace level tree\n");
     373    }
     374
     375    // Only display this message if it's trace level is less than the level
     376    // of it's associatedcomponent.
     377    if (level <= psGetTraceLevel(comp)) {
    432378        va_start(ap, level);
    433379
     
    444390        va_end(ap);
    445391    }
     392
    446393    // NOTE: should we free *fmt as well?  Read the man page.
    447394}
  • trunk/psLib/src/sys/psTrace.h

    r556 r560  
    11#if !defined(PS_TRACE_H)
    22#define PS_TRACE_H 1
    3 #define UNKNOWN_TRACE_LEVEL -9999               // we don't know this name's level
     3#define UNKNOWN_TRACE_LEVEL -9999         // we don't know this name's level
     4#define DEFAULT_TRACE_LEVEL 0
    45
    56/** \file psTrace.h
     
    78 *  \ingroup SystemGroup
    89 */
     10
     11/*****************************************************************************
     12    A component is a string of the form aaa.bbb.ccc, and may itself contain
     13    further subcomponents.  The Component structure doesn't in fact contain
     14    it's full name, but only the last part.
     15 *****************************************************************************/
     16typedef struct Component
     17{
     18    const char *name;                     // last part of name of component
     19    int level;                            // trace level for this component
     20    int n;                                // number of subcomponents
     21    struct Component **subcomp;           // next level of subcomponents
     22}
     23Component;
    924
    1025/** Functions **************************************************************/
     
    2843;
    2944
    30 /// turn off all tracing, and free trace's allocated memory
    31 void psTraceReset(void)
     45/// Set all trace levels to zero (do not free nodes in the component tree).
     46void psTraceReset()
     47;
     48
     49/// Free all nodes in the component tree.
     50void psTraceFree()
    3251;
    3352
  • trunk/psLib/src/sysUtils/psHash.c

    r494 r560  
    1313#include "psTrace.h"
    1414
    15 // A bucket that holds an item of data
    16 typedef struct HashBucket
    17 {
    18     char *key;    // key for this item of data
    19     void *data;    // the data itself
    20     struct HashBucket *next;  // list of other possible keys
    21 }
    22 HashBucket;
    23 
    24 // An entire hash table
    25 struct HashTable
    26 {
    27     int nbucket;   // number of buckets
    28     HashBucket **buckets;  // the buckets themselves
    29 };
    30 
    31 /******************************************************************************
    32     Con/Destruct buckets
    33  *****************************************************************************/
    34 static HashBucket *hashBucketAlloc(const char *key,
    35                                    void *data,
    36                                    HashBucket *next)
    37 {
    38     HashBucket *bucket = psAlloc(sizeof(HashBucket));
     15/******************************************************************************
     16    Construct buckets
     17 *****************************************************************************/
     18static psHashBucket *hashBucketAlloc(const char *key,
     19                                     void *data,
     20                                     psHashBucket *next)
     21{
     22    psHashBucket *bucket = psAlloc(sizeof(psHashBucket));
    3923
    4024    bucket->key = psStringCopy(key);
     
    4630
    4731/******************************************************************************
    48  
    49  *****************************************************************************/
    50 static void hashBucketFree(
    51     HashBucket *bucket,   // bucket to free
    52     void (*itemFree)(void *item)) // how to free hashed data;
    53 // or NULL
     32    Destruct buckets
     33 *****************************************************************************/
     34static void hashBucketFree(psHashBucket *bucket,   // bucket to free
     35                           void (*itemFree)(void *item)) // how to free data;
    5436{
    5537    if (bucket == NULL)
     
    7557{
    7658    psHash *table = psAlloc(sizeof(psHash));
    77     table->buckets = psAlloc(nbucket*sizeof(HashBucket *));
     59    table->buckets = psAlloc(nbucket*sizeof(psHashBucket *));
    7860    table->nbucket = nbucket;
    7961
     
    10486    {
    10587        if (table->buckets[i] != NULL) {
    106             HashBucket *ptr = table->buckets[i];
     88            psHashBucket *ptr = table->buckets[i];
    10789            while (ptr != NULL) {
    108                 HashBucket *tmp = ptr->next;
     90                psHashBucket *tmp = ptr->next;
    10991                hashBucketFree(ptr, itemFree);
    11092                ptr = tmp;
     
    124106    N.b. this is NOT a good hash function! See Knuth for some better ones
    125107 *****************************************************************************/
    126 static void *doHashWork(
    127     psHash *table,   // table to insert in
    128     const char *key,   // key to use
    129     void *data,    // data to insert,
    130     // or (if NULL) retrieve/remove
    131     int remove
    132         ,    // remove the item from the list?
    133         void (*itemFree)(void *item)) // how to free hashed data
    134     // or NULL
     108static void *doHashWork(psHash     *table,   // table to insert in
     109                        const char *key,     // key to use
     110                        void       *data,    // data to insert,
     111                        // or (if NULL) retrieve/remove
     112                        int remove
     113                            ,          // remove the item from the list?
     114                            void (*itemFree)(void *item))
     115    // how to free hashed data
    135116{
    136117    long int hash = 1;
     
    142123    hash &= (table->nbucket - 1);
    143124
    144     HashBucket *ptr = table->buckets[hash];
    145     /*
    146      * We've found the correct hash bucket, now we need to know what to do
    147      */
     125    psHashBucket *ptr = table->buckets[hash];
     126
     127    // We've found the correct hash bucket, now we need to know what to do
    148128    if (data == NULL) {   // retrieve/remove
    149129        if (remove
    150130           ) {
    151             HashBucket *optr = ptr;
     131            psHashBucket *optr = ptr;
    152132            while (ptr != NULL) {
    153133                if (strcmp(key, ptr->key) == 0) { // found it!
     
    196176            }
    197177        }
    198         /*
    199          * Not found, so insert at the front of the list
    200          */
     178
     179        // Not found, so insert at the front of the list
    201180        table->buckets[hash] = hashBucketAlloc(key, data, table->buckets[hash]);
    202181
     
    208187    Insert a value into a hash table
    209188 *****************************************************************************/
    210 void *psHashInsert(psHash *table, // table to insert in
     189void *psHashInsert(psHash *table,   // table to insert in
    211190                   const char *key, // key to use
    212                    void *data,  // data to insert
     191                   void *data,      // data to insert
    213192                   void (*itemFree)(void *item)) // how to free hashed data;
    214 // or NULL
    215193{
    216194    return doHashWork(table, key, data, 0, itemFree);
     
    220198    Lookup a value in a hash table
    221199 *****************************************************************************/
    222 void *psHashLookup(psHash *table, // table to lookup key in
     200void *psHashLookup(psHash *table,   // table to lookup key in
    223201                   const char *key) // key to lookup
    224202{
     
    229207    Remove and return a value from a hash table
    230208 *****************************************************************************/
    231 void *psHashRemove(psHash *table, // table to lookup key in
     209void *psHashRemove(psHash *table,   // table to lookup key in
    232210                   const char *key) // key to lookup
    233211{
  • trunk/psLib/src/sysUtils/psHash.h

    r494 r560  
    88
    99/** DO WE NEED TO DEFINE HashTable? */
    10 typedef struct HashTable psHash; ///< Opaque type for a hash table
     10//typedef struct HashTable psHash; ///< Opaque type for a hash table
     11// An entire hash table
     12
     13// A bucket that holds an item of data
     14typedef struct psHashBucket
     15{
     16    char *key;                          // key for this item of data
     17    void *data;                         // the data itself
     18    struct psHashBucket *next;          // list of other possible keys
     19}
     20psHashBucket;
     21
     22typedef struct psHash
     23{
     24    int nbucket;
     25    psHashBucket **buckets;
     26}
     27psHash;
    1128
    1229/** Functions **************************************************************/
     
    1936
    2037/// Free hash buckets from table.
    21 void psHashFree(psHash *table,  ///< hash table to be freed
     38void psHashFree(psHash *table,               ///< hash table to be freed
    2239                void (*itemFree)(void *item) ///< how to free hashed data; or NULL
    2340               );
    2441
    2542/// Insert entry into table.
    26 void *psHashInsert(psHash *table, ///< table to insert in
    27                    const char *key, ///< key to use
    28                    void *data,  ///< data to insert
     43void *psHashInsert(psHash *table,               ///< table to insert in
     44                   const char *key,             ///< key to use
     45                   void *data,                  ///< data to insert
    2946                   void (*itemFree)(void *item) ///< how to free hashed data; or NULL
    3047                  );
  • trunk/psLib/src/sysUtils/psLogMsg.c

    r500 r560  
    261261        head_ptr += strlen(head_ptr);
    262262    }
     263
    263264    if (head_ptr > head) {
    264265        *head_ptr++ = '|';
     
    269270    case PS_LOG_TO_STDOUT:
    270271        puts(head);
    271         vprintf(fmt, ap);
    272         if (fmt[strlen(fmt) - 1] != '\n') {
     272        if (log_msg) {
     273            vprintf(fmt, ap);
     274            if (fmt[strlen(fmt) - 1] != '\n') {
     275                putc('\n', stdout);
     276            }
     277        } else {
    273278            putc('\n', stdout);
    274279        }
     
    277282    case PS_LOG_TO_STDERR:
    278283        fputs(head, stderr);
    279         vfprintf(stderr, fmt, ap);
    280         if (fmt[strlen(fmt) - 1] != '\n') {
     284        if (log_msg) {
     285            vfprintf(stderr, fmt, ap);
     286            if (fmt[strlen(fmt) - 1] != '\n') {
     287                putc('\n', stderr);
     288            }
     289        } else {
    281290            putc('\n', stderr);
    282291        }
  • trunk/psLib/src/sysUtils/psTrace.c

    r559 r560  
    11/*****************************************************************************
    2     A simple implementation of a tracing facility for Pan-STARRS
    3  
    4     Tracing is controlled on a per "component" basis, where a "component" is
    5     a name of the form aaa.bbb.ccc where aaa is the most significant part.
    6     For example, the utilities library might be called "utils", the
    7     doubly-linked list "utils.dlist", and the code to destroy a list
    8     "utils.dlist.del".
     2    A simple implementation of a tracing facility for Pan-STARRS.  Tracing
     3    is controlled on a per "component" basis, where a "component" is a name
     4    of the form aaa.bbb.ccc where aaa is the most significant part.
    95 
    106    NOTES:
    11  In the SRD, higher trace levels correspond to a numerically lower
    12  trace value in the code.  This is a bit confusing.
     7 In the SRD, higher trace levels correspond to a numerically lower trace
     8 value in the code.  This is a bit confusing.  For example, a high-level
     9 message might be something like "Begin Processing".  The module programmer
     10 might give that a numerically low trace level, such as 1, so then any
     11 non-zero trace level in that code component will display thatmessage.
    1312 
    1413 We build a tree of trace components.  Every node in the tree has a
    1514 depth, which is it's distance from the root.  However, this is not
    1615 not the same thing as a node's "level", which corresponds to the
    17  trace level of that node.  I should probably rename some variables.
    18  
    19  This code is obduscated by the fact that component names are of the form
     16 trace level of that node.
     17 
     18 This code is obfuscated by the fact that component names are of the form
    2019 ".a.b.c.d" where "." is always the root of the tree, and for tree that have
    2120 a depth of 3 or higher (including the root ".") the "."  character is also
     
    2423 while the last three dots merely act as separators between the node names
    2524 "b", "c", and "d".
     25 
     26 I added a function psTraceFree() which frees all nodes in the trace component
     27 tree.  Previously, there had been no function in the API which accomplished
     28 this purpose.
    2629 *****************************************************************************/
    2730#include <stdlib.h>
     
    2932#include <string.h>
    3033#include <stdarg.h>
    31 /* #include "psLib.h" */
     34/* #include "pslib.h" */
    3235#include "psMemory.h"
    3336#include "psTrace.h"
    3437#include "psString.h"
    35 
    36 #define CACHE_NAME_LEN 50
    37 #define NO_CACHE "\a"                     // no name is cached
    38 /*****************************************************************************
    39     A component is a string of the form aaa.bbb.ccc, and may itself contain
    40     further subcomponents.  The Component structure doesn't in fact contain
    41     it's full name, but only the last part.
    42  *****************************************************************************/
    43 typedef struct Component
    44 {
    45     const char *name;                     // last part of name of component
    46     int level;                            // trace level for this component
    47     int dimen;                            // dimension of subcomponents
    48     int n;                                // number of subcomponents
    49     struct Component **subcomp;           // next level of subcomponents
    50 }
    51 Component;
     38#include "psError.h"
    5239
    5340static Component *croot = NULL;           // The root of the trace component
    54 // tree.
    55 
    56 // NOTE: the next tree globals exist for optimization purposes only.
    57 // Consider removing them.
    58 static int highest_level = 0;             // Highest level requested.  Defining
    59 // this variable allows us to reduce component-tree searches that tell
    60 // us if a message should be printed.
    61 static char cachedName[CACHE_NAME_LEN + 1] = NO_CACHE;
    62 // last name looked up
    63 static int cachedLevel;                   // level of last looked up name
    64 
    65 
    6641/*****************************************************************************
    6742    componentAlloc(): allocate memory for a new node, and initialize members.
     
    7045                          int level)
    7146{
    72     //printf("Calling componentAlloc(%s, %d)\n", name, level);
    7347    Component *comp = psAlloc(sizeof(Component));
    7448    comp->name = psStringCopy(name);
    7549    comp->level = level;
    76     comp->dimen = comp->n = 0;
     50    comp->n = 0;
    7751    comp->subcomp = NULL;
    7852    return comp;
     
    10882{
    10983    if (croot == NULL) {
    110         croot = componentAlloc(".", UNKNOWN_TRACE_LEVEL);
    111     }
    112 }
    113 
    114 
    115 /*****************************************************************************
    116     Free the trace tree information
    117  *****************************************************************************/
    118 void psTraceReset(void)
     84        croot = componentAlloc(".", DEFAULT_TRACE_LEVEL);
     85    }
     86}
     87
     88
     89/*****************************************************************************
     90    Set all trace levels to zero.
     91 *****************************************************************************/
     92void p_psTraceReset(Component *currentNode)
     93{
     94    int i = 0;
     95
     96    if (NULL == currentNode) {
     97        return;
     98    }
     99
     100    currentNode->level = 0;
     101    for (i=0;i<currentNode->n;i++) {
     102        if (NULL == currentNode->subcomp[i]) {
     103            psError(__func__,
     104                    "Sub-component %d of node %s in the trace tree is NULL.\n",
     105                    i, currentNode->name);
     106        } else {
     107            p_psTraceReset(currentNode->subcomp[i]);
     108        }
     109    }
     110    return;
     111}
     112
     113void psTraceReset()
     114{
     115    p_psTraceReset(croot);
     116}
     117
     118
     119void psTraceFree()
    119120{
    120121    componentFree(croot);
    121     croot = NULL;
    122122}
    123123
     
    140140    int        nodeExists = 0;
    141141
    142     // printf("Calling componentAdd(%s, %d)\n", addNodeName, level);
    143142    // Is this the root node?  If so, simply set level and return.
    144143    if (strcmp(".", addNodeName) == 0) {
     
    185184
    186185/*****************************************************************************
    187     setHighestLevel(): traverse the component tree recursively.  For each
    188  node encountered, if it's trace level is higher than the global
    189  variable highest_level, then set highest_level to that nodes trace
    190  level.
    191     Input:
    192  comp
    193     Output:
    194  none
    195     Returns:
    196  NULL
    197  *****************************************************************************/
    198 static void setHighestLevel(const Component *comp)
    199 {
    200     int i = 0;
    201 
    202     if (comp == NULL) {
    203         printf("ERROR: setHighestLevel(NULL)\n");
    204         exit(1);
    205     }
    206 
    207     // If this nodes trace level is the max so far, save it in highest_level
    208     if (comp->level > highest_level) {
    209         highest_level = comp->level;
    210     }
    211 
    212     // Do the same for all children nodes.
    213     for (i = 0; i < comp->n; i++) {
    214         setHighestLevel(comp->subcomp[i]);
    215     }
    216 }
    217 
    218 
    219 /*****************************************************************************
    220186    psSetTraceLevel(): add the component named "comp" to the component tree,
    221187 if it is not already there, and set it's trace level to "level".
     
    236202    }
    237203
    238     //printf("Calling psSetTraceLevel(%s, %d)\n", comp, level);
    239     // invalidate cache
    240     strncpy(cachedName, NO_CACHE, CACHE_NAME_LEN);
    241 
    242204    // Add the new component to the component tree.
    243205    componentAdd(comp, level);
    244206
    245     // Save this search info in our depth-one cache.
    246     if (level > highest_level) {
    247         highest_level = level;
    248     } else {
    249         highest_level = UNKNOWN_TRACE_LEVEL;
    250         setHighestLevel(croot);
    251     }
    252 
    253207    // return 0 on success.
    254     //printf("Called psSetTraceLevel(%s, %d)\n", comp, level);
    255208    return 0;
    256209}
     
    279232    int        i = 0;
    280233
     234    if (NULL == currentNode) {
     235        return(UNKNOWN_TRACE_LEVEL);
     236    }
     237
    281238    if (strcmp(".", aname) == 0) {
    282239        return(croot->level);
     
    292249        firstComponent = strsep(&pname, ".");
    293250        for (i = 0; i < currentNode->n; i++) {
     251            if (NULL == currentNode->subcomp[i]) {
     252                psError(__func__,
     253                        "Sub-component %d of node %s in trace tree is NULL.\n",
     254                        i, currentNode->name);
     255            }
     256
    294257            if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
    295258                currentNode = currentNode->subcomp[i];
     
    318281int psGetTraceLevel(const char *name)
    319282{
    320     int level = -1;
    321 
    322     //printf("Calling psGetTraceLevel(%s)\n", name);
    323     // If the root component tree does not exist, then initialize it.
    324283    if (croot == NULL) {
    325         initTrace();
    326     }
    327 
    328     // Before we traverse the component tree, check if we just searched for
    329     // this name, and if so, return that level.
    330     if (strcmp(name, cachedName) == 0) {
    331         return cachedLevel;
     284        return(UNKNOWN_TRACE_LEVEL);
    332285    }
    333286
    334287    // Search the component root tree, determine the trace level.
    335     level = doGetTraceLevel(name);
    336 
    337     // Save this search info in our depth-one cache.
    338     strncpy(cachedName, name, CACHE_NAME_LEN);
    339     cachedLevel = level;
    340 
    341     //printf("Called psGetTraceLevel(%s) (level was %d)\n", name, level);
    342     return level;
     288    return(doGetTraceLevel(name));
    343289}
    344290
     
    392338void psPrintTraceLevels(void)
    393339{
    394     // If the root component tree does not exist, then initialize it.
    395340    if (croot == NULL) {
    396         initTrace();
     341        return;
    397342    }
    398343
     
    423368    int i = 0;
    424369
    425     // We first check if the level of this message is less than the highest
    426     // level in the tree.  If so, we don't go any further.  If not, we need
    427     // to determine the trace level of comp, and then display the message if
    428     // the comp's trace level is high enough.
    429 
    430     if ((level <= highest_level) &&
    431             (level <= psGetTraceLevel(comp))) {
     370    if (NULL == comp) {
     371        psError(__func__,
     372                "p_psTrace() called on a NULL trace level tree\n");
     373    }
     374
     375    // Only display this message if it's trace level is less than the level
     376    // of it's associatedcomponent.
     377    if (level <= psGetTraceLevel(comp)) {
    432378        va_start(ap, level);
    433379
     
    444390        va_end(ap);
    445391    }
     392
    446393    // NOTE: should we free *fmt as well?  Read the man page.
    447394}
  • trunk/psLib/src/sysUtils/psTrace.h

    r556 r560  
    11#if !defined(PS_TRACE_H)
    22#define PS_TRACE_H 1
    3 #define UNKNOWN_TRACE_LEVEL -9999               // we don't know this name's level
     3#define UNKNOWN_TRACE_LEVEL -9999         // we don't know this name's level
     4#define DEFAULT_TRACE_LEVEL 0
    45
    56/** \file psTrace.h
     
    78 *  \ingroup SystemGroup
    89 */
     10
     11/*****************************************************************************
     12    A component is a string of the form aaa.bbb.ccc, and may itself contain
     13    further subcomponents.  The Component structure doesn't in fact contain
     14    it's full name, but only the last part.
     15 *****************************************************************************/
     16typedef struct Component
     17{
     18    const char *name;                     // last part of name of component
     19    int level;                            // trace level for this component
     20    int n;                                // number of subcomponents
     21    struct Component **subcomp;           // next level of subcomponents
     22}
     23Component;
    924
    1025/** Functions **************************************************************/
     
    2843;
    2944
    30 /// turn off all tracing, and free trace's allocated memory
    31 void psTraceReset(void)
     45/// Set all trace levels to zero (do not free nodes in the component tree).
     46void psTraceReset()
     47;
     48
     49/// Free all nodes in the component tree.
     50void psTraceFree()
    3251;
    3352
  • trunk/psLib/test/sysUtils/Makefile

    r557 r560  
    33##  Makefile:   test/sysUtils
    44##
    5 ##  $Revision: 1.5 $  $Name: not supported by cvs2svn $
    6 ##  $Date: 2004-04-30 06:19:57 $
     5##  $Revision: 1.6 $  $Name: not supported by cvs2svn $
     6##  $Date: 2004-05-01 23:04:35 $
    77##
    88##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1010###############################################################################
    1111
     12###############################################################################
     13#    Note: I added specific entries for the psTrace files.  The reason I did
     14#    this was because the generic rules were failing on the existing test
     15#    code (and hence, on my tst_psTraceXX.c code as well).  I am tempted to
     16#    fix the generic rules, but that might break existing codes.  When this
     17#    problem is resolved, I'll remove the specific rules for psTrace.  -GLG
     18#    Also, psLogMsg.
     19#    Also, psHash.
     20###############################################################################
    1221include ../../src/Makefile.Globals
    1322
     
    2029         atst_psAbort_02    \
    2130         atst_psAbort_03    \
    22          tst_psTrace00      \
    23          tst_psTrace01      \
    24          tst_psTrace02      \
    25          tst_psTrace03      \
    2631         tst_psStringCopy
     32TARGET_TRACE = tst_psTrace00 tst_psTrace01 tst_psTrace02 tst_psTrace03 \
     33               tst_psTrace04
     34TARGET_LOGMSG = tst_psLogMsg00 tst_psLogMsg01 tst_psLogMsg02 tst_psLogMsg03
     35TARGET_HASH = tst_psHash00 tst_psHash01 tst_psHash02 tst_psHash03 tst_psHash04
    2736
    28 all: $(TARGET)
     37all:            $(TARGET)
     38psTrace:        $(TARGET_TRACE)
     39psLogMsg:       $(TARGET_LOGMSG)
     40psHash: $(TARGET_HASH)
    2941
    3042tst_psError: tst_psError.o
     
    3749        @echo "    Deleting executable and binary files for 'test/sysUtils'"
    3850        $(RM) $(TARGET) *.o *.lint
     51
     52tst_psHash00:   tst_psHash00.c
     53        $(CC) tst_psHash00.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psHash00
     54
     55tst_psHash01:   tst_psHash01.c
     56        $(CC) tst_psHash01.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psHash01
     57
     58tst_psHash02:   tst_psHash02.c
     59        $(CC) tst_psHash02.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psHash02
     60
     61tst_psHash03:   tst_psHash03.c
     62        $(CC) tst_psHash03.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psHash03
     63
     64tst_psHash04:   tst_psHash04.c
     65        $(CC) tst_psHash04.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psHash04
     66
     67tst_psLogMsg00: tst_psLogMsg00.c
     68        $(CC) tst_psLogMsg00.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psLogMsg00
     69
     70tst_psLogMsg01: tst_psLogMsg01.c
     71        $(CC) tst_psLogMsg01.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psLogMsg01
     72
     73tst_psLogMsg02: tst_psLogMsg02.c
     74        $(CC) tst_psLogMsg02.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psLogMsg02
     75
     76tst_psLogMsg03: tst_psLogMsg03.c
     77        $(CC) tst_psLogMsg03.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psLogMsg03
    3978
    4079tst_psTrace00:  tst_psTrace00.c
     
    5089        $(CC) tst_psTrace03.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psTrace03
    5190
     91tst_psTrace04:  tst_psTrace04.c
     92        $(CC) tst_psTrace04.c $(LDFLAGS) -L$(PSLIB_LIB_DIR) -L.. -lpslib -lpstest -I$(PSLIB_INCL_DIR) -I.. -o tst_psTrace04
     93
    5294%.o : %.c
    5395        $(CC) $(CFLAGS) $(CPPFLAGS) -I.. -I$(PSLIB_INCL_DIR) -c -o $@ $<
     
    60102
    61103distclean:
    62         rm DistCleanFiles
     104        rm -rf $(TARGET_TRACE) $(TARGET_LOGMSG) $(TARGET_HASH)
  • trunk/psLib/test/sysUtils/tst_psTrace00.c

    r558 r560  
    1010    int i = 0;
    1111    int lev = 0;
    12     int errorFlag = true;
     12    int testStatus = true;
    1313
    14     printPositiveTestHeader(stderr,
     14    printPositiveTestHeader(stdout,
    1515                            "psTrace functions",
    16                             "Testing psSetTraceLevel and psGetTraceLevel");
     16                            "psSetTraceLevel() and psGetTraceLevel()");
    1717    for (i=0;i<10;i++) {
    1818        psSetTraceLevel(".", i);
     
    2121            printf("ERROR: (.) expected trace level was %d, actual was %d\n",
    2222                   i, lev);
    23             errorFlag = false;
     23            testStatus = false;
    2424        }
    2525    }
     
    3232            printf("ERROR: (.NODE00) expected trace level was %d, actual was %d\n",
    3333                   i, lev);
    34             errorFlag = false;
     34            testStatus = false;
    3535        }
    3636
     
    3939            printf("ERROR: (.) expected trace level was %d, actual was %d\n",
    4040                   i, 3);
    41             errorFlag = false;
     41            testStatus = false;
    4242        }
    4343    }
     
    5151            printf("ERROR: (.NODE00.NODE01) expected trace level was %d, actual was %d\n",
    5252                   i, lev);
    53             errorFlag = false;
     53            testStatus = false;
    5454        }
    5555    }
    5656
    57     printFooter(stderr,
     57    printFooter(stdout,
    5858                "psTrace functions",
    5959                "Testing psSetTraceLevel and psGetTraceLevel",
    60                 errorFlag);
    61     exit(0);
     60                testStatus);
     61    exit(!testStatus);
    6262}
  • trunk/psLib/test/sysUtils/tst_psTrace01.c

    r555 r560  
    1212    int successFlag = true;
    1313
    14     printPositiveTestHeader(stderr,
     14    printPositiveTestHeader(stdout,
    1515                            "psTrace functions",
    16                             "Testing psTraceReset()");
     16                            "psTraceReset()");
    1717
    1818    for (i=0;i<10;i++) {
     
    2121
    2222        lev = psGetTraceLevel(".");
    23         if (lev != UNKNOWN_TRACE_LEVEL) {
     23        if (lev != DEFAULT_TRACE_LEVEL) {
    2424            printf("ERROR: expected trace level was %d, actual was %d\n",
    2525                   i, lev);
     
    3232    psSetTraceLevel(".a.b.c", 2);
    3333    psTraceReset();
    34     if ((UNKNOWN_TRACE_LEVEL != psGetTraceLevel(".")) ||
    35             (UNKNOWN_TRACE_LEVEL != psGetTraceLevel(".a")) ||
    36             (UNKNOWN_TRACE_LEVEL != psGetTraceLevel(".a.b")) ||
    37             (UNKNOWN_TRACE_LEVEL != psGetTraceLevel(".a.b.c"))) {
     34    if ((DEFAULT_TRACE_LEVEL != psGetTraceLevel(".")) ||
     35            (DEFAULT_TRACE_LEVEL != psGetTraceLevel(".a")) ||
     36            (DEFAULT_TRACE_LEVEL != psGetTraceLevel(".a.b")) ||
     37            (DEFAULT_TRACE_LEVEL != psGetTraceLevel(".a.b.c"))) {
    3838        printf("ERROR: trace levels were not reset properly\n");
    3939        successFlag = false;
    4040    }
    4141
    42     printFooter(stderr,
     42    printFooter(stdout,
    4343                "psTrace functions",
    44                 "Testing psTraceReset()",
     44                "psTraceReset()",
    4545                successFlag);
    46     exit(0);
     46
     47    exit(!successFlag);
    4748}
  • trunk/psLib/test/sysUtils/tst_psTrace02.c

    r555 r560  
    1212    int lev = 0;
    1313    int errorFlag = 0;
     14
     15    printPositiveTestHeader(stdout,
     16                            "psTrace functions",
     17                            "psTrace()");
    1418
    1519    psSetTraceLevel(".", 4);
     
    3539            0xbeefface);
    3640
     41    printFooter(stdout,
     42                "psTrace functions",
     43                "psTrace()",
     44                true);
     45
    3746    exit(0);
    3847}
  • trunk/psLib/test/sysUtils/tst_psTrace03.c

    r558 r560  
    99main()
    1010{
     11    printPositiveTestHeader(stdout,
     12                            "psTrace functions",
     13                            "psTracePrintLevels()");
     14
    1115    psSetTraceLevel(".", 9);
    1216
     
    2630
    2731    psPrintTraceLevels();
     32
     33    printFooter(stdout,
     34                "psTrace functions",
     35                "psTracePrintLevels()",
     36                true);
     37
    2838    exit(0);
    2939}
  • trunk/psLib/test/sysUtils/verified/tst_psTrace00.stderr

    r554 r560  
    1 /----------------------------- TESTPOINT --------------------------------\
    2 |   TestFile: tst_psTrace00.c                                            |
    3 |  TestPoint: psTrace functions{Testing psSetTraceLevel and psGetTraceLevel} |
    4 |   TestType: Positive                                                   |
    5 \------------------------------------------------------------------------/
    6 
    7 
    8 ---> TESTPOINT PASSED (psTrace functions{Testing psSetTraceLevel and psGetTraceLevel} | tst_psTrace00.c)
    9 
  • trunk/psLib/test/sysUtils/verified/tst_psTrace00.stdout

    r554 r560  
     1/----------------------------- TESTPOINT --------------------------------\
     2|   TestFile: tst_psTrace00.c                                            |
     3|  TestPoint: psTrace functions{psSetTraceLevel() and psGetTraceLevel()} |
     4|   TestType: Positive                                                   |
     5\------------------------------------------------------------------------/
     6
     7
     8---> TESTPOINT PASSED (psTrace functions{Testing psSetTraceLevel and psGetTraceLevel} | tst_psTrace00.c)
     9
  • trunk/psLib/test/sysUtils/verified/tst_psTrace01.stderr

    r554 r560  
    1 /----------------------------- TESTPOINT --------------------------------\
    2 |   TestFile: tst_psTrace01.c                                            |
    3 |  TestPoint: psTrace functions{Testing psTraceReset()}                  |
    4 |   TestType: Positive                                                   |
    5 \------------------------------------------------------------------------/
    6 
    7 
    8 ---> TESTPOINT PASSED (psTrace functions{Testing psTraceReset()} | tst_psTrace01.c)
    9 
  • trunk/psLib/test/sysUtils/verified/tst_psTrace01.stdout

    r554 r560  
     1/----------------------------- TESTPOINT --------------------------------\
     2|   TestFile: tst_psTrace01.c                                            |
     3|  TestPoint: psTrace functions{psTraceReset()}                          |
     4|   TestType: Positive                                                   |
     5\------------------------------------------------------------------------/
     6
     7
     8---> TESTPOINT PASSED (psTrace functions{psTraceReset()} | tst_psTrace01.c)
     9
  • trunk/psLib/test/sysUtils/verified/tst_psTrace02.stdout

    r554 r560  
     1/----------------------------- TESTPOINT --------------------------------\
     2|   TestFile: tst_psTrace02.c                                            |
     3|  TestPoint: psTrace functions{psTrace()}                               |
     4|   TestType: Positive                                                   |
     5\------------------------------------------------------------------------/
     6
    17     (0) This message should be displayed (beefface)
    28     (1) This message should be displayed (beefface)
    39     (2) This message should be displayed (beefface)
     10
     11---> TESTPOINT PASSED (psTrace functions{psTrace()} | tst_psTrace02.c)
     12
  • trunk/psLib/test/sysUtils/verified/tst_psTrace03.stdout

    r558 r560  
     1/----------------------------- TESTPOINT --------------------------------\
     2|   TestFile: tst_psTrace03.c                                            |
     3|  TestPoint: psTrace functions{psTracePrintLevels()}                    |
     4|   TestType: Positive                                                   |
     5\------------------------------------------------------------------------/
     6
    17.                    9
    28 a                   8
     
    1016  b                  3
    1117  c                  5
     18
     19---> TESTPOINT PASSED (psTrace functions{psTracePrintLevels()} | tst_psTrace03.c)
     20
Note: See TracChangeset for help on using the changeset viewer.