1 : /*
2 : * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : /*
8 : * Test for kernel version parsing routines.
9 : */
10 :
11 : #include "gtest/gtest.h"
12 : #include "native_client/src/include/nacl_macros.h"
13 : #include "native_client/src/include/nacl_platform.h"
14 : #include "native_client/src/shared/platform/nacl_log.h"
15 : #include "native_client/src/trusted/platform_qualify/kernel_version.h"
16 :
17 :
18 : struct TestData {
19 : const char *version;
20 : int ok;
21 : int num1;
22 : int num2;
23 : int num3;
24 : };
25 :
26 :
27 : class KernelVersionTest : public testing::Test {
28 : protected:
29 : virtual void SetUp();
30 : virtual void TearDown();
31 : };
32 :
33 1 : void KernelVersionTest::SetUp() {
34 1 : NaClLogModuleInit();
35 1 : }
36 :
37 1 : void KernelVersionTest::TearDown() {
38 1 : NaClLogModuleFini();
39 1 : }
40 :
41 3 : TEST_F(KernelVersionTest, ParseKernelVersion) {
42 : TestData tests[] = {
43 1 : { "1.2.3", 1, 1, 2, 3 },
44 1 : { "1.2", 1, 1, 2, 0 },
45 1 : { "2.6.27", 1, 2, 6, 27 },
46 1 : { "2.6.28-smp", 1, 2, 6, 28 },
47 1 : { "2.6.30.8-experimental4", 1, 2, 6, 30 },
48 1 : { "3.0-rc4", 1, 3, 0, 0 },
49 1 : { "zsdjff", 0, 0, 0, 0 },
50 1 : { "10.6", 1, 10, 6, 0 },
51 1 : { "10.4-intel", 1, 10, 4, 0 },
52 1 : { "10-intel", 0, 0, 0, 0 },
53 : };
54 1 : for (size_t i = 0; i < NACL_ARRAY_SIZE(tests); i++) {
55 : int num1, num2, num3;
56 : ASSERT_EQ(tests[i].ok, NaClParseKernelVersion(tests[i].version,
57 1 : &num1, &num2, &num3));
58 1 : if (!tests[i].ok) {
59 1 : continue;
60 : }
61 1 : EXPECT_EQ(tests[i].num1, num1);
62 1 : EXPECT_EQ(tests[i].num2, num2);
63 1 : EXPECT_EQ(tests[i].num3, num3);
64 1 : }
65 1 : }
66 :
67 : struct CompareTestData {
68 : const char* v1;
69 : const char* v2;
70 : int ok;
71 : int res;
72 : };
73 :
74 3 : TEST_F(KernelVersionTest, CompareKernelVersions) {
75 : CompareTestData tests[] = {
76 1 : { "1.2.3", "1.2.4", 1, -1 },
77 1 : { "2.6.26.90", "2.6.27", 1, -1 },
78 1 : { "3.0", "2.6.27", 1, 1 },
79 1 : { "zz", "2.6.27", 0, 0 },
80 1 : { "2.6.37.1", "2.6.37.1", 1, 0 },
81 1 : { "2.6.37.1", "2.6.37.2", 1, 0 },
82 1 : { "10.6.8", "10.8", 1, -1 },
83 1 : { "10.8", "10.7", 1, 1 },
84 : };
85 1 : for (size_t i = 0; i < NACL_ARRAY_SIZE(tests); i++) {
86 : int res;
87 : ASSERT_EQ(tests[i].ok, NaClCompareKernelVersions(tests[i].v1,
88 : tests[i].v2,
89 1 : &res));
90 1 : if (!tests[i].ok) {
91 1 : continue;
92 : }
93 1 : EXPECT_EQ(tests[i].res, res);
94 1 : }
95 1 : }
96 :
97 1 : int main(int argc, char **argv) {
98 1 : testing::InitGoogleTest(&argc, argv);
99 1 : return RUN_ALL_TESTS();
100 1 : }
|