test/service: fix race condition on stopping lcore
[dpdk.git] / app / test / test_resource.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016 RehiveTech. All rights reserved.
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7
8 #include "test.h"
9 #include "resource.h"
10
11 const char test_resource_dpdk_blob[] = {
12         '\x44', '\x50', '\x44', '\x4b', '\x00'
13 };
14
15 REGISTER_RESOURCE(test_resource_dpdk,
16                 test_resource_dpdk_blob, test_resource_dpdk_blob + 4);
17
18 static int test_resource_dpdk(void)
19 {
20         const struct resource *r;
21
22         r = resource_find("test_resource_dpdk");
23         TEST_ASSERT_NOT_NULL(r, "Could not find test_resource_dpdk");
24         TEST_ASSERT(!strcmp(r->name, "test_resource_dpdk"),
25                         "Found resource %s, expected test_resource_dpdk",
26                         r->name);
27
28         TEST_ASSERT(!strncmp("DPDK", r->begin, 4),
29                         "Unexpected payload: %.4s...", r->begin);
30
31         return 0;
32 }
33
34 REGISTER_LINKED_RESOURCE(test_resource_c);
35
36 static int test_resource_c(void)
37 {
38         const struct resource *r;
39         FILE *f;
40
41         r = resource_find("test_resource_c");
42         TEST_ASSERT_NOT_NULL(r, "No test_resource_c found");
43         TEST_ASSERT(!strcmp(r->name, "test_resource_c"),
44                         "Found resource %s, expected test_resource_c",
45                         r->name);
46
47         TEST_ASSERT_SUCCESS(resource_fwrite_file(r, "test_resource.c"),
48                         "Failed to to write file %s", r->name);
49
50         f = fopen("test_resource.c", "r");
51         TEST_ASSERT_NOT_NULL(f,
52                         "Missing extracted file resource.c");
53         fclose(f);
54         remove("test_resource.c");
55
56         return 0;
57 }
58
59 #ifdef RTE_APP_TEST_RESOURCE_TAR
60 REGISTER_LINKED_RESOURCE(test_resource_tar);
61
62 static int test_resource_tar(void)
63 {
64         const struct resource *r;
65         FILE *f;
66
67         r = resource_find("test_resource_tar");
68         TEST_ASSERT_NOT_NULL(r, "No test_resource_tar found");
69         TEST_ASSERT(!strcmp(r->name, "test_resource_tar"),
70                         "Found resource %s, expected test_resource_tar",
71                         r->name);
72
73         TEST_ASSERT_SUCCESS(resource_untar(r),
74                         "Failed to to untar %s", r->name);
75
76         f = fopen("test_resource.c", "r");
77         TEST_ASSERT_NOT_NULL(f,
78                         "Missing extracted file test_resource.c");
79         fclose(f);
80
81         TEST_ASSERT_SUCCESS(resource_rm_by_tar(r),
82                         "Failed to remove extracted contents of %s", r->name);
83         return 0;
84 }
85
86 #endif /* RTE_APP_TEST_RESOURCE_TAR */
87
88 static int test_resource(void)
89 {
90         if (test_resource_dpdk())
91                 return -1;
92
93         if (test_resource_c())
94                 return -1;
95
96 #ifdef RTE_APP_TEST_RESOURCE_TAR
97         if (test_resource_tar())
98                 return -1;
99 #endif /* RTE_APP_TEST_RESOURCE_TAR */
100
101         return 0;
102 }
103
104 REGISTER_TEST_COMMAND(resource_autotest, test_resource);