iPXE
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(...)
 Define inline data.
#define PROFILE_TEST(name, MEAN, STDDEV, SAMPLES)
 Define a profiling test.
#define profile_ok(test)

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.

Macro Definition Documentation

◆ DATA

#define DATA ( ...)
Value:
{ __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:1986
A profiling test.

Define a profiling test.

Definition at line 56 of file profile_test.c.

56#define PROFILE_TEST( name, MEAN, STDDEV, SAMPLES ) \
57 static const unsigned long name ## _samples[] = SAMPLES; \
58 static struct profile_test name = { \
59 .samples = name ## _samples, \
60 .count = ( sizeof ( name ## _samples ) / \
61 sizeof ( name ## _samples [0] ) ), \
62 .mean = MEAN, \
63 .stddev = STDDEV, \
64 }

◆ profile_ok

#define profile_ok ( test)
Value:
profile_okx ( test, __FILE__, __LINE__ )
static int test
Definition epic100.c:73
static void profile_okx(struct profile_test *test, const char *file, unsigned int line)
Report a profiling test result.

Definition at line 122 of file profile_test.c.

Referenced by profile_test_exec().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ PROFILE_TEST() [1/7]

PROFILE_TEST ( empty ,
0 ,
0 ,
DATA()  )

Empty data set.

◆ PROFILE_TEST() [2/7]

PROFILE_TEST ( zero ,
0 ,
0 ,
DATA(0)  )

Single-element data set (zero)

References DATA.

◆ PROFILE_TEST() [3/7]

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

Single-element data set (non-zero)

References DATA.

◆ PROFILE_TEST() [4/7]

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

Multiple identical element data set.

References DATA.

◆ PROFILE_TEST() [5/7]

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

Small element data set.

References DATA.

◆ 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.

References DATA, and random().

◆ 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.

References DATA.

◆ profile_okx()

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 */
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}
#define DBGC(...)
Definition compiler.h:505
void * memset(void *dest, int character, size_t len) __nonnull
unsigned long profile_mean(struct profiler *profiler)
Get mean sample value.
Definition profile.c:242
unsigned long profile_stddev(struct profiler *profiler)
Get sample standard deviation.
Definition profile.c:276
void profile_update(struct profiler *profiler, unsigned long sample)
Update profiler with a new sample.
Definition profile.c:111
A data structure for storing profiling information.
Definition profile.h:27
unsigned long mean
Mean sample value (scaled)
Definition profile.h:37
#define okx(success, file, line)
Report test result.
Definition test.h:44

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

◆ profile_test_exec()

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}
#define profile_ok(test)
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition random.c:32

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.

Profiling self-test.

Definition at line 141 of file profile_test.c.

141 {
142 .name = "profile",
143 .exec = profile_test_exec,
144};