Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
bootloader_test.cc
1 #include <gtest/gtest.h>
2 
3 #include "bootloader.h"
4 #include "storage/invstorage.h"
5 
6 /* Check that the reboot detection feature works */
7 TEST(bootloader, detectReboot) {
8  TemporaryDirectory temp_dir;
9  StorageConfig storage_config;
10  storage_config.path = temp_dir.Path();
11  std::shared_ptr<INvStorage> storage = INvStorage::newStorage(storage_config);
12 
13  BootloaderConfig boot_config;
14  boot_config.reboot_sentinel_dir = temp_dir.Path();
15  Bootloader bootloader(boot_config, *storage);
16 
17  ASSERT_TRUE(bootloader.supportRebootDetection());
18 
19  // nothing happened should not flag a reboot
20  ASSERT_FALSE(bootloader.rebootDetected());
21 
22  // we flagged an expected reboot but did not reboot yet
23  bootloader.rebootFlagSet();
24  ASSERT_FALSE(bootloader.rebootDetected());
25 
26  // simulate the reboot: loss of a temporary file
27  boost::filesystem::remove(boot_config.reboot_sentinel_dir / boot_config.reboot_sentinel_name);
28  ASSERT_TRUE(bootloader.rebootDetected());
29 
30  // should still flag if not cleared
31  ASSERT_TRUE(bootloader.rebootDetected());
32 
33  // stop flagging when cleared
34  bootloader.rebootFlagClear();
35  ASSERT_FALSE(bootloader.rebootDetected());
36 }
37 
38 #ifndef __NO_MAIN__
39 int main(int argc, char **argv) {
40  ::testing::InitGoogleTest(&argc, argv);
41  return RUN_ALL_TESTS();
42 }
43 #endif
StorageConfig
Definition: config.h:111
Bootloader
Definition: bootloader.h:8
TemporaryDirectory
Definition: utils.h:82
BootloaderConfig
Definition: config.h:156