[sim] Add support for disabling SimDevices (#2568)

This allows disabling/enabling SimDevices via prefix matching.  This can be
used to force devices that normally use SimDevice in simulation mode to
instead talk directly to the hardware as in normal operation.
This commit is contained in:
Peter Johnson
2020-07-04 01:09:49 -07:00
committed by GitHub
parent 1851ba1434
commit 80a1fa9ece
6 changed files with 101 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "gtest/gtest.h"
#include "hal/SimDevice.h"
#include "hal/simulation/SimDeviceData.h"
namespace hal {
TEST(SimDeviceSimTests, TestEnabled) {
ASSERT_TRUE(HALSIM_IsSimDeviceEnabled("foo"));
HALSIM_SetSimDeviceEnabled("f", false);
HALSIM_SetSimDeviceEnabled("foob", true);
ASSERT_FALSE(HALSIM_IsSimDeviceEnabled("foo"));
ASSERT_TRUE(HALSIM_IsSimDeviceEnabled("foobar"));
ASSERT_TRUE(HALSIM_IsSimDeviceEnabled("bar"));
ASSERT_EQ(HAL_CreateSimDevice("foo"), 0);
}
} // namespace hal