iPXE
Data Structures | Defines | Functions | Variables
profile_test.c File Reference

Profiling self-tests. More...

#include <string.h>
#include <assert.h>
#include <ipxe/test.h>
#include <ipxe/profile.h>

Go to the source code of this file.

Data Structures

struct  profile_test
 A profiling test. More...

Defines

#define DATA(...)   { __VA_ARGS__ }
 Define inline data.
#define PROFILE_TEST(name, MEAN, STDDEV, SAMPLES)
 Define a profiling test.
#define profile_ok(test)   profile_okx ( test, __FILE__, __LINE__ )

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 PROFILE_TEST (empty, 0, 0, DATA())
 Empty data set.
 PROFILE_TEST (zero, 0, 0, DATA(0))
 Single-element data set (zero)
 PROFILE_TEST (single, 42, 0, DATA(42))
 Single-element data set (non-zero)
 PROFILE_TEST (identical, 69, 0, DATA(69, 69, 69, 69, 69, 69, 69))
 Multiple identical element data set.
 PROFILE_TEST (small, 5, 2, DATA(3, 5, 9, 4, 3, 2, 5, 7))
 Small element data set.
 PROFILE_TEST (random, 70198, 394, DATA(69772, 70068, 70769, 69653, 70663, 71078, 70101, 70341, 70215, 69600, 70020, 70456, 70421, 69972, 70267, 69999, 69972))
 Random data set.
 PROFILE_TEST (large, 93533894UL, 25538UL, DATA(93510333UL, 93561169UL, 93492361UL, 93528647UL, 93557566UL, 93503465UL, 93540126UL, 93549020UL, 93502307UL, 93527320UL, 93537152UL, 93540125UL, 93550773UL, 93586731UL, 93521312UL))
 Large-valued random data set.
static void profile_okx (struct profile_test *test, const char *file, unsigned int line)
 Report a profiling test result.
static void profile_test_exec (void)
 Perform profiling self-tests.

Variables

struct self_test profile_test __self_test
 Profiling self-test.

Detailed Description

Profiling self-tests.

Definition in file profile_test.c.


Define Documentation

#define DATA (   ...)    { __VA_ARGS__ }

Define inline data.

Definition at line 53 of file profile_test.c.

#define PROFILE_TEST (   name,
  MEAN,
  STDDEV,
  SAMPLES 
)
Value:
static const unsigned long name ## _samples[] = SAMPLES;        \
        static struct profile_test name = {                             \
                .samples = name ## _samples,                            \
                .count = ( sizeof ( name ## _samples ) /                \
                           sizeof ( name ## _samples [0] ) ),           \
                .mean = MEAN,                                           \
                .stddev = STDDEV,                                       \
        }

Define a profiling test.

Definition at line 56 of file profile_test.c.

#define profile_ok (   test)    profile_okx ( test, __FILE__, __LINE__ )

Definition at line 122 of file profile_test.c.

Referenced by profile_test_exec().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
PROFILE_TEST ( empty  ,
,
,
DATA()   
)

Empty data set.

PROFILE_TEST ( zero  ,
,
,
DATA(0)   
)

Single-element data set (zero)

PROFILE_TEST ( single  ,
42  ,
,
DATA(42)   
)

Single-element data set (non-zero)

PROFILE_TEST ( identical  ,
69  ,
,
DATA(69, 69, 69, 69, 69, 69, 69)   
)

Multiple identical element data set.

PROFILE_TEST ( small  ,
,
,
DATA(3, 5, 9, 4, 3, 2, 5, 7)   
)

Small element data set.

PROFILE_TEST ( random  ,
70198  ,
394  ,
DATA(69772, 70068, 70769, 69653, 70663, 71078, 70101, 70341, 70215, 69600, 70020, 70456, 70421, 69972, 70267, 69999, 69972)   
)

Random data set.

PROFILE_TEST ( large  ,
93533894UL  ,
25538UL  ,
DATA(93510333UL, 93561169UL, 93492361UL, 93528647UL, 93557566UL, 93503465UL, 93540126UL, 93549020UL, 93502307UL, 93527320UL, 93537152UL, 93540125UL, 93550773UL, 93586731UL, 93521312UL)   
)

Large-valued random data set.

static void profile_okx ( struct profile_test test,
const char *  file,
unsigned int  line 
) [static]

Report a profiling test result.

Parameters:
testProfiling test
fileTest code file
lineTest code line

Definition at line 101 of file profile_test.c.

References profile_test::count, DBGC, profiler::mean, profile_test::mean, memset(), okx, profile_mean(), profile_stddev(), profile_update(), profile_test::samples, and profile_test::stddev.

                                              {
        struct profiler profiler;
        unsigned long mean;
        unsigned long stddev;
        unsigned int i;

        /* Initialise profiler */
        memset ( &profiler, 0, sizeof ( profiler ) );

        /* Record sample values */
        for ( i = 0 ; i < test->count ; i++ )
                profile_update ( &profiler, test->samples[i] );

        /* Check resulting statistics */
        mean = profile_mean ( &profiler );
        stddev = profile_stddev ( &profiler );
        DBGC ( test, "PROFILE calculated mean %ld stddev %ld\n", mean, stddev );
        okx ( mean == test->mean, file, line );
        okx ( stddev == test->stddev, file, line );
}
static void profile_test_exec ( void  ) [static]

Perform profiling self-tests.

Definition at line 128 of file profile_test.c.

References profile_ok, random(), and zero.

                                       {

        /* Perform profiling tests */
        profile_ok ( &empty );
        profile_ok ( &zero );
        profile_ok ( &single );
        profile_ok ( &identical );
        profile_ok ( &small );
        profile_ok ( &random );
        profile_ok ( &large );
}

Variable Documentation

Initial value:
 {
        .name = "profile",
        .exec = profile_test_exec,
}

Profiling self-test.

Definition at line 141 of file profile_test.c.