-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_functions.c
104 lines (89 loc) · 2.31 KB
/
test_functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "test_functions.h"
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// test asynchronous/synchronous call mechanism (and a void return value)
void sleep_test1(uint32_t arg)
{
sleep(arg);
}
void sleep_test2(uint32_t arg)
{
fprintf(stdout, "stdout writing before %d second sleep\n", arg);
sleep(arg);
fprintf(stdout, "stdout writing after %d second sleep\n", arg);
fprintf(stderr, "stderr\nline\nbreak(s)\nmissing");
}
uint64_t integer_test1()
{
return 0xffffffffffffffff;
}
char char_test1(char a)
{
return a;
}
unsigned char char_test2(unsigned char a)
{
return a;
}
float float_test1()
{
const float x = 1.0f / 3.0f;
return (x * 3.0 - 1.0);
}
static char pchar_test1_data[128];
char * pchar_test1(char * p, uint32_t length)
{
memcpy(pchar_test1_data, p, length);
pchar_test1_data[length] = '\0';
return pchar_test1_data;
}
static char time_test1_data[128];
char * time_test1(time_t t)
{
return ctime_r(&t, time_test1_data);
}
float float_test2(double value)
{
return (float) value;
}
int32_t integer_test2(int8_t size1, int16_t size2,
int32_t size4, int64_t size8)
{
return size1 + size2 + size4 +
((size8 & 0x7fffffff) | ((size8 & 0x8000000000000000) >> 32));
}
uint32_t integer_test3(uint8_t size1, uint16_t size2,
uint32_t size4, uint64_t size8)
{
return size1 + size2 + size4 + (size8 & 0xffffffff);
}
static char pchar_test2_data[128];
char * pchar_test2(char * p1, uint32_t l1, char c1,
char * p2, uint32_t l2, char c2,
char * p3, uint32_t l3, char c3)
{
memcpy(&pchar_test2_data[0], p1, l1);
pchar_test2_data[l1] = c1;
memcpy(&pchar_test2_data[l1 + 1], p2, l2);
pchar_test2_data[l1 + l2 + 1] = c2;
memcpy(&pchar_test2_data[l1 + l2 + 2], p3, l3);
pchar_test2_data[l1 + l2 + l3 + 2] = c3;
pchar_test2_data[l1 + l2 + l3 + 3] = '\0';
return pchar_test2_data;
}
pchar_len_t hello_test1()
{
pchar_len_t hello;
char const * message = "Hello World!";
/* do not include a '\0' character,
* Erlang detects it is a binary string with magic!
*/
hello.pchar = malloc(12);
memcpy(hello.pchar, message, 12);
hello.length = 12;
return hello;
}