V0.8.0 Arroyo Toad

Fixed problems related to concurrency and segmentation faults
This commit is contained in:
Christian Risi
2024-12-17 15:07:12 +00:00
parent 2ef8cc868b
commit d05a2c3767
10 changed files with 237 additions and 153 deletions

View File

@@ -11,10 +11,10 @@ import MessageUtils
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
let sensor : Sensor = Sensor(id: 1, sensorType: .Temperature)
let data = sensor.read(env)
let sensor : IdealSensor = IdealSensor(id: 1, sensorType: .Temperature)
let data = await sensor.read(env)
#expect(data.value == truth.value, "If values match, we are cool")
@@ -27,10 +27,10 @@ import MessageUtils
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
let sensor : Sensor = Sensor(id: 1, sensorType: .Temperature, faulty: true)
let data = sensor.read(env)
let sensor : IdealSensor = IdealSensor(id: 1, sensorType: .Temperature, faulty: true)
let data = await sensor.read(env)
#expect(data.value != truth.value, "If these match, something is not working")
@@ -43,10 +43,10 @@ import MessageUtils
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
let sensor : Sensor = RealSensor(sensorID: 1, sensorType: .Temperature, faulty: false, meanNoise: 0.5, stdNoise: 0.25, quantizationBits: 3)
let data = sensor.read(env)
let data = await sensor.read(env)
#expect(data.value - truth.value < 10, "If these match, we are cool")
@@ -61,10 +61,10 @@ import MessageUtils
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
let sensor : Sensor = RealSensor(sensorID: 1, sensorType: .Temperature, faulty: true, meanNoise: 0.5, stdNoise: 0.25, quantizationBits: 3)
let data = sensor.read(env)
let data = await sensor.read(env)
#expect(data.value - truth.value > 10, "If these match, something is not working")
@@ -79,22 +79,22 @@ import MessageUtils
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
let signKeyPath = "./Private/privateKey.pem"
let privateKey = try pem2_P256key(filePath: signKeyPath)
let dev: EdgeDevice = await EdgeDevice(
let dev: EdgeDevice = EdgeDevice(
deviceID: 1,
dataType: .Temperature,
disconnected: false,
location: Location(x: 20, y: 10, z: 0),
dutyCicle: 100098,
sensors: [
0: Sensor(id: 0, sensorType: DataType.Temperature),
1: Sensor(id: 0, sensorType: DataType.Temperature),
2: Sensor(id: 0, sensorType: DataType.Temperature, faulty: true)
0: IdealSensor(id: 0, sensorType: DataType.Temperature),
1: IdealSensor(id: 0, sensorType: DataType.Temperature),
2: IdealSensor(id: 0, sensorType: DataType.Temperature, faulty: true)
],
privateKey: try pem2_P256key(filePath: signKeyPath)
)
@@ -121,13 +121,13 @@ import MessageUtils
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
let signKeyPath = "./Private/privateKey.pem"
let privateKey = try pem2_P256key(filePath: signKeyPath)
let dev: EdgeDevice = await EdgeDevice(
let dev: EdgeDevice = EdgeDevice(
deviceID: 1,
dataType: .Temperature,
disconnected: false,

View File

@@ -10,9 +10,9 @@ import MessageUtils
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
IoTSimulatorCore.addEnv(environment: env)
await IoTSimulatorCore.addEnv(environment: env)
let signKeyPath = "./Private/privateKey.pem"
@@ -36,7 +36,7 @@ import MessageUtils
privateKey: try pem2_P256key(filePath: signKeyPath)
)
let dev2: EdgeDevice = await EdgeDevice(
let dev2: EdgeDevice = EdgeDevice(
deviceID: 2,
dataType: .Temperature,
disconnected: false,
@@ -56,7 +56,7 @@ import MessageUtils
privateKey: try pem2_P256key(filePath: signKeyPath)
)
try IoTSimulatorCore.addDevice(location: "Delta", device: dev, success: { msg in
try await IoTSimulatorCore.addDevice(location: "Delta", device: dev, success: { msg in
print(msg)
let _signedMessage = try! deserializeV1(serializedData: msg)
print(_signedMessage.toString())
@@ -64,7 +64,7 @@ import MessageUtils
failure: {
print("Something went wrong")
})
try IoTSimulatorCore.addDevice(location: "Delta", device: dev2, success: { msg in
try await IoTSimulatorCore.addDevice(location: "Delta", device: dev2, success: { msg in
print(msg)
let _signedMessage = try! deserializeV1(serializedData: msg)
print(_signedMessage.toString())
@@ -79,14 +79,14 @@ import MessageUtils
@Test func stressLoop1() async throws {
let devices: UInt128 = 5000
let devices: UInt128 = 1000000
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
IoTSimulatorCore.addEnv(environment: env)
await IoTSimulatorCore.addEnv(environment: env)
let signKeyPath = "./Private/privateKey.pem"
@@ -94,6 +94,8 @@ import MessageUtils
for i: UInt128 in 0..<devices {
print("\n\nCreating dev \(i)\n\n")
let dev: EdgeDevice = EdgeDevice(
deviceID: i,
dataType: .Temperature,
@@ -114,7 +116,7 @@ import MessageUtils
privateKey: try pem2_P256key(filePath: signKeyPath)
)
try IoTSimulatorCore.addDevice(
try await IoTSimulatorCore.addDevice(
location: "Delta",
device: dev,
success: { msg in
@@ -136,21 +138,21 @@ import MessageUtils
sleep(1)
}
print("NUKE EM ALLLLLLLLLL!!!!!\n\n")
IoTSimulatorCore.nukeAll()
await IoTSimulatorCore.nukeAll()
}
@Test func stressLoop2() async throws {
let devices: UInt128 = 1
let devices: UInt128 = 10
let env = PhysicalEnvironment("Delta")
let truth = PhysicalData(.Temperature, 22)
env.setPhysicalData(DataType.Temperature, truth)
await env.setPhysicalData(DataType.Temperature, truth)
IoTSimulatorCore.addEnv(environment: env)
await IoTSimulatorCore.addEnv(environment: env)
let signKeyPath = "./Private/privateKey.pem"
@@ -178,7 +180,7 @@ import MessageUtils
privateKey: try pem2_P256key(filePath: signKeyPath)
)
try IoTSimulatorCore.addDevice(location: "Delta", device: dev, success: { msg in
try await IoTSimulatorCore.addDevice(location: "Delta", device: dev, success: { msg in
print(msg)
let _signedMessage = try deserializeV1(serializedData: msg)
print(_signedMessage.toString())
@@ -193,12 +195,11 @@ import MessageUtils
for i in 0..<_sleep {
print("Hi, at \(i)s\n\n")
sleep(1)
await IoTSimulatorCore.toggleSensor(devID: 0, sensorID: 0)
await IoTSimulatorCore.toggleSensor(devID: UInt.random(in: 0..<UInt(devices)), sensorID: 0)
}
print("NUKE EM ALLLLLLLLLL!!!!!\n\n")
IoTSimulatorCore.nukeAll()
await IoTSimulatorCore.nukeAll()
}