PX4 Firmware
PX4 Autopilot Software http://px4.io
test_versioning.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file test_versioning.c
36  * Tests automatic versioning functionality.
37  */
38 
39 #include <unit_test.h>
40 #include <version/version.h>
41 
42 class VersioningTest : public UnitTest
43 {
44 public:
45  virtual bool run_tests();
46 
47 private:
48  bool _test_tag_to_version_number(const char *version_tag, uint32_t flight_version_target,
49  uint32_t vendor_version_target);
50 };
51 
52 bool VersioningTest::_test_tag_to_version_number(const char *version_tag, uint32_t flight_version_target,
53  uint32_t vendor_version_target)
54 {
55  uint32_t flight_version_result = version_tag_to_number(version_tag);
56  uint32_t vendor_version_result = version_tag_to_vendor_version_number(version_tag);
57 
58  if (flight_version_target == flight_version_result) {
59  if (vendor_version_target == vendor_version_result) {
60  return true;
61 
62  } else {
63  PX4_ERR("Wrong vendor version: tag: %s, got: 0x%x, expected: 0x%x", version_tag, vendor_version_result,
64  vendor_version_target);
65  return false;
66  }
67 
68  } else {
69  PX4_ERR("Wrong flight version: tag: %s, got: 0x%x, expected: 0x%x", version_tag, flight_version_result,
70  flight_version_target);
71  return false;
72  }
73 }
74 
76 {
77  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3", 0x0B2D63FF, 0x010203FF));
78  ut_assert_true(_test_tag_to_version_number("v11.45.99-01.02.03", 0x0B2D63FF, 0x010203FF));
79  ut_assert_true(_test_tag_to_version_number("v011.045.099-001.002.003", 0x0B2D63FF, 0x010203FF));
80  ut_assert_true(_test_tag_to_version_number("v011.045.099-1.2.3", 0x0B2D63FF, 0x010203FF));
81  ut_assert_true(_test_tag_to_version_number("v1.2.3", 0x010203FF, 0x000000FF));
82  ut_assert_true(_test_tag_to_version_number("v255.255.255", 0xFFFFFFFF, 0x000000FF));
83  ut_assert_true(_test_tag_to_version_number("v255.255.255-11", 0xFFFFFF00, 0x00000000));
84  ut_assert_true(_test_tag_to_version_number("v255.255.255-255.255.255", 0xFFFFFFFF, 0xFFFFFFFF));
85  ut_assert_true(_test_tag_to_version_number("v255.255.255-0.0.0", 0xFFFFFFFF, 0x000000FF));
86  ut_assert_true(_test_tag_to_version_number("v0.0.0-0.0.0", 0x000000FF, 0x000000FF));
87  ut_assert_true(_test_tag_to_version_number("v0.0.0-255.255.255", 0x000000FF, 0xFFFFFFFF));
88  ut_assert_true(_test_tag_to_version_number("v1.2.3-111", 0x01020300, 0x00000000));
89  ut_assert_true(_test_tag_to_version_number("v1.2.3-11-gabababab", 0x01020300, 0x00000000));
90  ut_assert_true(_test_tag_to_version_number("11.45.99-1.2.3", 0x0B2D63FF, 0x010203FF));
91  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3rc3-7-g7e282f57", 0x0B2D6300, 0x01020300));
92  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3-rc3-7-g7e282f57", 0x0B2D6300, 0x01020300));
93  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3rc4", 0x0B2D63C0, 0x010203C0));
94  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3alpha3-7-g7e282f57", 0x0B2D6300, 0x01020300));
95  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3-alpha3-7-g7e282f57", 0x0B2D6300, 0x01020300));
96  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3alpha4", 0x0B2D6340, 0x01020340));
97  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3-alpha4", 0x0B2D6340, 0x01020340));
98  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3beta3-7-g7e282f57", 0x0B2D6300, 0x01020300));
99  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3-beta3-7-g7e282f57", 0x0B2D6300, 0x01020300));
100  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3beta4", 0x0B2D6380, 0x01020380));
101  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3-beta4", 0x0B2D6380, 0x01020380));
102  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3dev4", 0x0B2D6300, 0x01020300));
103  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3dev3-7-g7e282f57", 0x0B2D6300, 0x01020300));
104  ut_assert_true(_test_tag_to_version_number("0.45.99-1.2.3beta4", 0x002D6380, 0x01020380));
105  ut_assert_true(_test_tag_to_version_number("0.45.99-1.2.3-beta4", 0x002D6380, 0x01020380));
106  ut_assert_true(_test_tag_to_version_number("0.0.0-1.2.3beta4", 0x00000080, 0x01020380));
107  ut_assert_true(_test_tag_to_version_number("0.0.0-1.2.3-beta4", 0x00000080, 0x01020380));
108  ut_assert_true(_test_tag_to_version_number("0.0.0-1.2.3dev4", 0x00000000, 0x01020300));
109  ut_assert_true(_test_tag_to_version_number("v1.6.2-1.0.0", 0x010602FF, 0x010000FF));
110  ut_assert_true(_test_tag_to_version_number("v1.6.2-1.0.0rc2", 0x010602C0, 0x010000C0));
111  ut_assert_true(_test_tag_to_version_number("v1.6.2-1.0.0-rc2", 0x010602C0, 0x010000C0));
112  ut_assert_true(_test_tag_to_version_number("v1.6.2-1.0.0-rc2-gabababab", 0x01060200, 0x01000000));
113  ut_assert_true(_test_tag_to_version_number("v1.6.2-rc2", 0x010602C0, 0x000000C0));
114  ut_assert_true(_test_tag_to_version_number("v1.6.2rc1", 0x010602C0, 0x000000C0));
115  ut_assert_true(_test_tag_to_version_number("v1.6.10-100-g890c415", 0x01060A00, 0x00000000));
116  ut_assert_true(_test_tag_to_version_number("v1.6.10-99999999999999-g890c415", 0x01060A00, 0x00000000));
117  ut_assert_true(_test_tag_to_version_number("v1.6.2-0.8.7-67-g1d5e979", 0x01060200, 0x00080700));
118  ut_assert_true(_test_tag_to_version_number("randomtext", 0x00000000, 0x00000000));
119  ut_assert_true(_test_tag_to_version_number("randomtextwithnumber12", 0x00000000, 0x00000000));
120  ut_assert_true(_test_tag_to_version_number("12randomtextwithnumber", 0x00000000, 0x00000000));
121  ut_assert_true(_test_tag_to_version_number("12.12-randomtextwithnumber", 0x00000000, 0x00000000));
122  ut_assert_true(_test_tag_to_version_number("v12.12-randomtextwithnumber", 0x00000000, 0x00000000));
123  ut_assert_true(_test_tag_to_version_number("...-...", 0x00000000, 0x00000000));
124  ut_assert_true(_test_tag_to_version_number("v...-...", 0x00000000, 0x00000000));
125  ut_assert_true(_test_tag_to_version_number("v1.2.3-dirty", 0x01020300, 0x00000000));
126  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3-dirty", 0x0B2D6300, 0x01020300));
127  ut_assert_true(_test_tag_to_version_number("v1.2.3-111-dirty", 0x01020300, 0x00000000));
128  ut_assert_true(_test_tag_to_version_number("v1.2.3-11-gabababab-dirty", 0x01020300, 0x00000000));
129  ut_assert_true(_test_tag_to_version_number("v1.2.3-11-g1d5e979-dirty", 0x01020300, 0x00000000));
130  ut_assert_true(_test_tag_to_version_number("v1.4.9-1.2.3rc3-7-g7e282f57-dirty", 0x01040900, 0x01020300));
131  ut_assert_true(_test_tag_to_version_number("v1.4.9-1.2.3-rc3-7-g7e282f57-dirty", 0x01040900, 0x01020300));
132  ut_assert_true(_test_tag_to_version_number("v1.4.9-1.2.3alpha-7-g7e282f5-dirty", 0x01040900, 0x01020300));
133  ut_assert_true(_test_tag_to_version_number("v1.4.9-1.2.3-alpha-7-g7e282f5-dirty", 0x01040900, 0x01020300));
134  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3alpha4-dirty", 0x0B2D6300, 0x01020300));
135  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3-alpha4-dirty", 0x0B2D6300, 0x01020300));
136  ut_assert_true(_test_tag_to_version_number("v1.4.9-1.2.3beta-7-g7e282f57-dirty", 0x01040900, 0x01020300));
137  ut_assert_true(_test_tag_to_version_number("v1.4.9-1.2.3-beta-7-g7e282f57-dirty", 0x01040900, 0x01020300));
138  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3beta4-dirty", 0x0B2D6300, 0x01020300));
139  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3-beta4-dirty", 0x0B2D6300, 0x01020300));
140  ut_assert_true(_test_tag_to_version_number("v11.45.99-1.2.3dev4-dirty", 0x0B2D6300, 0x01020300));
141  ut_assert_true(_test_tag_to_version_number("v1.4.9-1.2.3dev3-7-g7e282f57-dirty", 0x01040900, 0x01020300));
142  ut_assert_true(_test_tag_to_version_number("v1.6.2-1.0.0rc2-dirty", 0x01060200, 0x01000000));
143  ut_assert_true(_test_tag_to_version_number("v1.6.2-1.0.0-rc2-dirty", 0x01060200, 0x01000000));
144  ut_assert_true(_test_tag_to_version_number("v1.6.2-1.0.0-rc2-gabababab-dirty", 0x01060200, 0x01000000));
145  ut_assert_true(_test_tag_to_version_number("v1.6.2-1.0.0rc2-gabababab-dirty", 0x01060200, 0x01000000));
146  ut_assert_true(_test_tag_to_version_number("v1.6.2-rc2-dirty", 0x01060200, 0x00000000));
147  ut_assert_true(_test_tag_to_version_number("v1.6.2rc1-dirty", 0x01060200, 0x00000000));
148  ut_assert_true(_test_tag_to_version_number("v1.6.2rc1-67-g1d5e979-dirty", 0x01060200, 0x00000000));
149  ut_assert_true(_test_tag_to_version_number("v1.6.2-rc1-67-g1d5e979-dirty", 0x01060200, 0x00000000));
150  ut_assert_true(_test_tag_to_version_number("v1.6.2-0.8.7-67-g1d5e979-dirty", 0x01060200, 0x00080700));
151  ut_assert_true(_test_tag_to_version_number("v1.8.2alpha4-dirty", 0x01080200, 0x00000000));
152  ut_assert_true(_test_tag_to_version_number("v1.8.2-alpha4-dirty", 0x01080200, 0x00000000));
153  ut_assert_true(_test_tag_to_version_number("v1.8.2alpha4-67-g1d5e979-dirty", 0x01080200, 0x00000000));
154  ut_assert_true(_test_tag_to_version_number("v1.8.2-alpha4-67-g1d5e979-dirty", 0x01080200, 0x00000000));
155  ut_assert_true(_test_tag_to_version_number("v1.8.2beta4-dirty", 0x01080200, 0x00000000));
156  ut_assert_true(_test_tag_to_version_number("v1.8.2-beta4-dirty", 0x01080200, 0x00000000));
157  ut_assert_true(_test_tag_to_version_number("v1.8.2beta4-67-g1d5e979-dirty", 0x01080200, 0x00000000));
158  ut_assert_true(_test_tag_to_version_number("v1.8.2-beta4-67-g1d5e979-dirty", 0x01080200, 0x00000000));
159  ut_assert_true(_test_tag_to_version_number("v1.8.2dev4-dirty", 0x01080200, 0x00000000));
160  ut_assert_true(_test_tag_to_version_number("v1.8.2dev4-67-g1d5e979-dirty", 0x01080200, 0x00000000));
161 
162  return (_tests_failed == 0);
163 }
164 
virtual bool run_tests()
Override to run your unit tests.
bool _test_tag_to_version_number(const char *version_tag, uint32_t flight_version_target, uint32_t vendor_version_target)
Base class to be used for unit tests.
Definition: unit_test.h:54
int _tests_failed
The number of unit tests which failed.
Definition: unit_test.h:206
int test_versioning(int argc, char *argv[])
uint32_t version_tag_to_number(const char *tag)
Convert a version tag string to a number.
Definition: version.c:66
#define ut_assert_true(test)
To assert specifically to true.
Definition: unit_test.h:127
ut_declare_test_c(test_versioning, VersioningTest)
Tools for system version detection.
uint32_t version_tag_to_vendor_version_number(const char *tag)
Convert a version tag string to a vendor version number.
Definition: version.c:154