summaryrefslogtreecommitdiff
path: root/unittest/beluga-adaptor_interface.cpp
blob: 58c25fc5860fc25cf94e722f768376a18a9ddc9d (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtest/gtest.h>
#include <unistd.h>

#include <sys/stat.h>
#include <sys/types.h>

#include "sa_common.h"
#include "setup_system.h"
#include "adaptor_interface.h"

using ::testing::InitGoogleTest;

TEST(beluga_adaptor_interface, beluga_adaptor_sa_get_os_info){
    int ret = 0;
    os_info_s *os_info_h = NULL;
    char *buf = NULL;    

    _D("[UNIT_TEST] call sa_get_os_info~~~~~");
    os_info_h = (os_info_s *)malloc(sizeof(os_info_s));
    if (os_info_h != NULL) {
        memset(os_info_h, 0x0, sizeof(os_info_s));
        ret = sa_get_os_info(os_info_h);
        if (ret != -1) {
            // make json string
            buf = sa_create_os_info_json_string(os_info_h);
            //_D("json_str : %s", buf);
            if (buf != NULL){
                free(buf);
            }
            _D("[UNIT_TEST] os_info platformVer = %s",os_info_h->platformVer);
            _D("[UNIT_TEST] os_info baseOS version = %s",os_info_h->baseOSVer);
            _D("[UNIT_TEST] os_info docker version = %s",os_info_h->dockerVer);
        }
        if(os_info_h->platformVer)
            free(os_info_h->platformVer);
        if(os_info_h->baseOSVer)
            free(os_info_h->baseOSVer);
        if(os_info_h->dockerVer)
            free(os_info_h->dockerVer);
        free(os_info_h);
    }
    _D("[UNIT_TEST] os_info returned(%d) !!!!", ret);
    EXPECT_EQ(0, ret);
}

TEST(beluga_adaptor_interface, beluga_adaptor_sa_get_disk_info){
    int ret = 0;
    disk_info_s *disk_info_h = NULL;
    char *buf = NULL;    
    int index = 0;

    _D("[UNIT_TEST] call sa_get_disk_info~~~~~");
    disk_info_h = (disk_info_s *)malloc(sizeof(disk_info_s));
    if (disk_info_h != NULL) {
        memset(disk_info_h, 0x0, sizeof(disk_info_s));
        ret = sa_get_disk_info(disk_info_h);
        if (ret != -1) {
            // make json string
            buf = sa_create_disk_info_json_string(disk_info_h);
            //_D("json_str : %s", buf);
            if (buf != NULL) {                
                free(buf);
            }
            for (index = 0; index < disk_info_h->count; index++) {
                _D("disk_info[%d] path = %s", index, disk_info_h->disk[index].path);
                _D("disk_info[%d] free = %dM", index, disk_info_h->disk[index].free);
                _D("disk_info[%d] total = %dM", index, disk_info_h->disk[index].total);
                _D("disk_info[%d] used = %dM", index, disk_info_h->disk[index].used);
                _D("disk_info[%d] usedpercent = %.2f%%", index, (float)disk_info_h->disk[index].usedpercent/(float)100);
            }
        }

        for (index = 0; index < disk_info_h->count; index++) {
            if(disk_info_h->disk[index].path)
                free(disk_info_h->disk[index].path);
        }
        free(disk_info_h);
    }
    _D("[UNIT_TEST] os_info returned(%d) !!!!", ret);
    EXPECT_EQ(0, ret);
}

TEST(beluga_adaptor_interface, beluga_adaptor_sa_create_device_reboot_json_string){
    char *buf = NULL;
    int ret = 0;

    _D("[UNIT_TEST] sa_create_device_reboot_json_string()");
    buf = sa_create_device_reboot_json_string(ret);

    EXPECT_STRNE(NULL, buf);

    if (buf != NULL)
    {
        free(buf);
    }
}

/*
TEST(beluga_adaptor_interface, beluga_adaptor_sa_factory_restore){
    int ret = 0;
    char *buf = NULL;
    int buf_len = 0;
    int fdevice_restart = 0;

    _D("[UNIT_TEST] call sa_factory_restore~~~~~");
    ret = sa_factory_restore(fdevice_restart);

    buf = sa_create_factory_restore_json_string(ret);
    if (buf != NULL) {        
        free(buf);
    }
    _D("[UNIT_TEST] os_info returned(%d) !!!!", ret);
    EXPECT_EQ(0, ret);
}

TEST(beluga_adaptor_interface, beluga_adaptor_api_main_thread){

    pthread_t t_api;    
    int ret = 0;

    _D("[UNIT_TEST] pthread_create >>> API_MAIN !!!");
    ret = pthread_create(&t_api, NULL, &api_main_thread, (void *)NULL);
    if (ret < 0) {
        _E("[UNIT_TEST][API_MAIN] thread create error (ret=%d)", ret);
        ret = -1;
    }
    sleep(5);
    pthread_cancel(t_api);

    EXPECT_EQ(0, ret);
}
*/