-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
159 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from sutsim_fixtures import suts | ||
import pytest | ||
import os | ||
|
||
@pytest.fixture | ||
def device_map(): | ||
# Dictionary to map device names to their firmware paths | ||
return { | ||
"device": os.path.join(os.path.dirname(__file__), 'sim_artifacts', 'libfirmware.so'), | ||
# Add more devices and their respective firmware paths here if needed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,10 @@ | ||
import sutsim as simulator | ||
import sutsim | ||
import pytest | ||
import os | ||
|
||
def test_data_types(): | ||
# Path to the firmware shared library | ||
firmware_lib_path = os.path.join(os.path.dirname(__file__), 'sim_artifacts', 'libfirmware.so') | ||
|
||
# Initialize the simulator | ||
simulator.initSim("device", firmware_lib_path) | ||
|
||
# Set the temperature sensor data and verify it was set correctly | ||
simulator.setSutDataFloat("device.temperature_sensor.temperature", 100.0) | ||
simulator.getSutDataFloat("device.temperature_sensor.temperature") == 100.0 | ||
def test_temperature_sensor_reads(suts): | ||
suts["device"]["temperature_sensor.temperature"] = 100.0 | ||
assert suts["device"]["temperature_sensor.temperature"] == 100.0 | ||
|
||
for _ in range(25): | ||
simulator.runTick() | ||
sutsim.runTick() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import sutsim | ||
|
||
class SimWrapper: | ||
def __init__(self, device_map): | ||
""" | ||
Initialize the SimWrapper with a dictionary of devices and their corresponding firmware paths. | ||
""" | ||
self.devices = {} | ||
for device_name, firmware_path in device_map.items(): | ||
# Initialize each device with its firmware path | ||
sutsim.initSim(device_name, firmware_path) | ||
self.devices[device_name] = firmware_path | ||
|
||
def __getitem__(self, device_name): | ||
# Check if the device exists in the initialized list | ||
if device_name not in self.devices: | ||
raise KeyError(f"Device '{device_name}' not found.") | ||
return SimDevice(device_name) | ||
|
||
class SimDevice: | ||
def __init__(self, device_name): | ||
self.device_name = device_name | ||
|
||
def __getitem__(self, tag): | ||
full_key = f"{self.device_name}.{tag}" | ||
return sutsim.getSutData(full_key) | ||
|
||
def __setitem__(self, tag, value): | ||
full_key = f"{self.device_name}.{tag}" | ||
sutsim.setSutData(full_key, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import sutsim | ||
import pytest | ||
from sim_wrapper import SimWrapper | ||
|
||
@pytest.fixture | ||
def suts(device_map): | ||
""" | ||
Fixture to set up the simulator with the provided device map. | ||
""" | ||
return SimWrapper(device_map) |