-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.c
66 lines (58 loc) · 1.5 KB
/
tests.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
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "helpers.h"
static void test_get_hw_info(void **state)
{
hwinfo *hw = NULL;
hw = malloc(sizeof(hwinfo));
assert_non_null(hw);
hw = get_hw_info();
assert_int_not_equal(hw->ncpu, 0);
assert_int_not_equal(hw->memsize, 0);
assert_int_not_equal(hw->uptime, 0);
}
static void test_get_os_info(void **state)
{
osinfo *os = malloc(sizeof(osinfo));
assert_non_null(os);
os = get_os_info();
assert_string_not_equal(os->os_version, "");
assert_string_not_equal(os->os_family, "");
assert_string_not_equal(os->os_name, "");
assert_string_not_equal(os->os_arch, "");
}
static void test_dirfs(void **state)
{
char *p = dirfs("/");
assert_string_not_equal(p, "");
}
#ifdef __linux__
static void test_lookup_fstype(void **state)
{
char *type = lookup_fstype(1);
assert_string_equal(type, "<fs type unknown>");
}
#endif
static void test_get_proc_uptime(void **state)
{
pid_t pid = 1;
long long int t = 0;
t = get_proc_uptime(pid);
assert_int_not_equal(t, 0);
}
int main(void){
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_get_hw_info),
cmocka_unit_test(test_get_os_info),
cmocka_unit_test(test_get_proc_uptime),
cmocka_unit_test(test_dirfs),
#ifdef __linux__
cmocka_unit_test(test_lookup_fstype),
#endif
};
return cmocka_run_group_tests(tests, NULL, NULL);
}