iPXE
Data Structures | Macros | 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...
 

Macros

#define DATA(...)   { __VA_ARGS__ }
 Define inline data. More...
 
#define PROFILE_TEST(name, MEAN, STDDEV, SAMPLES)
 Define a profiling test. More...
 
#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. More...
 
 PROFILE_TEST (zero, 0, 0, DATA(0))
 Single-element data set (zero) More...
 
 PROFILE_TEST (single, 42, 0, DATA(42))
 Single-element data set (non-zero) More...
 
 PROFILE_TEST (identical, 69, 0, DATA(69, 69, 69, 69, 69, 69, 69))
 Multiple identical element data set. More...
 
 PROFILE_TEST (small, 5, 2, DATA(3, 5, 9, 4, 3, 2, 5, 7))
 Small element data set. More...
 
 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. More...
 
 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. More...
 
static void profile_okx (struct profile_test *test, const char *file, unsigned int line)
 Report a profiling test result. More...
 
static void profile_test_exec (void)
 Perform profiling self-tests. More...
 

Variables

struct self_test profile_test __self_test
 Profiling self-test. More...
 

Detailed Description

Profiling self-tests.

Definition in file profile_test.c.

Macro Definition Documentation

◆ DATA

#define DATA (   ...)    { __VA_ARGS__ }

Define inline data.

Definition at line 53 of file profile_test.c.

◆ PROFILE_TEST

#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, \
}
const char * name
Definition: ath9k_hw.c:1984
A profiling test.
Definition: profile_test.c:41
unsigned long stddev
Expected standard deviation.
Definition: profile_test.c:49
unsigned long mean
Expected mean sample value.
Definition: profile_test.c:47

Define a profiling test.

Definition at line 56 of file profile_test.c.

◆ profile_ok

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

Definition at line 122 of file profile_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ PROFILE_TEST() [1/7]

PROFILE_TEST ( empty  ,
,
,
DATA()   
)

Empty data set.

◆ PROFILE_TEST() [2/7]

PROFILE_TEST ( zero  ,
,
,
DATA(0)   
)

Single-element data set (zero)

◆ PROFILE_TEST() [3/7]

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

Single-element data set (non-zero)

◆ PROFILE_TEST() [4/7]

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

Multiple identical element data set.

◆ PROFILE_TEST() [5/7]

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

Small element data set.

◆ PROFILE_TEST() [6/7]

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() [7/7]

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.

◆ profile_okx()

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.

102  {
103  struct profiler profiler;
104  unsigned long mean;
105  unsigned long stddev;
106  unsigned int i;
107 
108  /* Initialise profiler */
109  memset ( &profiler, 0, sizeof ( profiler ) );
110 
111  /* Record sample values */
112  for ( i = 0 ; i < test->count ; i++ )
113  profile_update ( &profiler, test->samples[i] );
114 
115  /* Check resulting statistics */
116  mean = profile_mean ( &profiler );
117  stddev = profile_stddev ( &profiler );
118  DBGC ( test, "PROFILE calculated mean %ld stddev %ld\n", mean, stddev );
119  okx ( mean == test->mean, file, line );
120  okx ( stddev == test->stddev, file, line );
121 }
unsigned long profile_mean(struct profiler *profiler)
Get mean sample value.
Definition: profile.c:241
#define DBGC(...)
Definition: compiler.h:505
A data structure for storing profiling information.
Definition: profile.h:26
unsigned long profile_stddev(struct profiler *profiler)
Get sample standard deviation.
Definition: profile.c:275
#define okx(success, file, line)
Report test result.
Definition: test.h:44
void profile_update(struct profiler *profiler, unsigned long sample)
Update profiler with a new sample.
Definition: profile.c:110
unsigned long mean
Mean sample value (scaled)
Definition: profile.h:36
static int test
Definition: epic100.c:73
void * memset(void *dest, int character, size_t len) __nonnull

References DBGC, profiler::mean, memset(), okx, profile_mean(), profile_stddev(), profile_update(), and test.

◆ profile_test_exec()

static void profile_test_exec ( void  )
static

Perform profiling self-tests.

Definition at line 128 of file profile_test.c.

128  {
129 
130  /* Perform profiling tests */
131  profile_ok ( &empty );
132  profile_ok ( &zero );
133  profile_ok ( &single );
134  profile_ok ( &identical );
135  profile_ok ( &small );
136  profile_ok ( &random );
137  profile_ok ( &large );
138 }
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:31
#define profile_ok(test)
Definition: profile_test.c:122

References profile_ok, and random().

Variable Documentation

◆ __self_test

struct self_test profile_test __self_test
Initial value:
= {
.name = "profile",
}
static void profile_test_exec(void)
Perform profiling self-tests.
Definition: profile_test.c:128

Profiling self-test.

Definition at line 141 of file profile_test.c.