Skip to content

Commit

Permalink
Merge pull request #363 from Limmen/stopping_tests
Browse files Browse the repository at this point in the history
Stopping-game tests
  • Loading branch information
Limmen authored May 28, 2024
2 parents 7587d5d + 9651e20 commit caed7d0
Show file tree
Hide file tree
Showing 11 changed files with 1,563 additions and 25 deletions.
99 changes: 99 additions & 0 deletions simulation-system/libs/csle-tolerance/recovery_game.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
3 1 2 2 2 72 12 0.9
0 0
1 0
2 0
WAIT
RECOVER
FALSEALARM
ATTACK
o_0
o_1
0 1
0 1
0 1
0 1
0 0 0 0 0 0.06
0 0 0 1 0 0.04000000000000001
0 0 0 0 1 0.12
0 0 0 1 1 0.08000000000000002
0 0 0 0 2 0.42
0 0 0 1 2 0.27999999999999997
0 0 1 0 0 0.1
0 0 1 1 0 0.1
0 0 1 0 1 0.15
0 0 1 1 1 0.15
0 0 1 0 2 0.25
0 0 1 1 2 0.25
0 1 0 0 0 0.3
0 1 0 1 0 0.2
0 1 0 0 1 0.18
0 1 0 1 1 0.12
0 1 0 0 2 0.12
0 1 0 1 2 0.08000000000000002
0 1 1 0 0 0.15
0 1 1 1 0 0.15
0 1 1 0 1 0.2
0 1 1 1 1 0.2
0 1 1 0 2 0.15
0 1 1 1 2 0.15
1 0 0 0 0 0.18
1 0 0 1 0 0.12
1 0 0 0 1 0.24
1 0 0 1 1 0.16000000000000003
1 0 0 0 2 0.18
1 0 0 1 2 0.12
1 0 1 0 0 0.2
1 0 1 1 0 0.2
1 0 1 0 1 0.15
1 0 1 1 1 0.15
1 0 1 0 2 0.15
1 0 1 1 2 0.15
1 1 0 0 0 0.18
1 1 0 1 0 0.12
1 1 0 0 1 0.3
1 1 0 1 1 0.2
1 1 0 0 2 0.12
1 1 0 1 2 0.08000000000000002
1 1 1 0 0 0.25
1 1 1 1 0 0.25
1 1 1 0 1 0.2
1 1 1 1 1 0.2
1 1 1 0 2 0.05
1 1 1 1 2 0.05
2 0 0 0 0 0.12
2 0 0 1 0 0.08000000000000002
2 0 0 0 1 0.12
2 0 0 1 1 0.08000000000000002
2 0 0 0 2 0.36
2 0 0 1 2 0.24
2 0 1 0 0 0.15
2 0 1 1 0 0.15
2 0 1 0 1 0.15
2 0 1 1 1 0.15
2 0 1 0 2 0.2
2 0 1 1 2 0.2
2 1 0 0 0 0.24
2 1 0 1 0 0.16000000000000003
2 1 0 0 1 0.18
2 1 0 1 1 0.12
2 1 0 0 2 0.18
2 1 0 1 2 0.12
2 1 1 0 0 0.1
2 1 1 1 0 0.1
2 1 1 0 1 0.25
2 1 1 1 1 0.25
2 1 1 0 2 0.15
2 1 1 1 2 0.15
0 0 0 -1.0
0 0 1 -1.0
0 1 0 -4.0
0 1 1 -4.0
1 0 0 -2.0
1 0 1 -2.0
1 1 0 -5.0
1 1 1 -5.0
2 0 0 -3.0
2 0 1 -3.0
2 1 0 -6.0
2 1 1 -6.0
0 0.1 0.9
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ def generate_transitions(game_config: IntrusionRecoveryGameConfig) -> List[str]:
if prob > 0:
transition = f"{s} {a1} {a2} {i} {s_prime} {prob}"
transitions.append(transition)

return transitions

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
)
from csle_tolerance.util.intrusion_recovery_pomdp_util import IntrusionRecoveryPomdpUtil
import pytest_mock
import numpy as np


class TestIntrusionRecoveryGameConfigSuite:
Expand All @@ -28,7 +27,7 @@ def test__init__(self) -> None:
observations=[0, 1],
cost_tensor=[[1, 2], [3, 4]],
observation_tensor=[[1, 2], [3, 4]],
transition_tensor=[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]],
transition_tensor=[[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]]],
b1=[0.1, 0.9],
T=100,
simulation_env_name="sim_env",
Expand All @@ -48,8 +47,7 @@ def test__init__(self) -> None:
assert dto.cost_tensor == [[1, 2], [3, 4]]
assert dto.observation_tensor == [[1, 2], [3, 4]]
assert dto.transition_tensor == [
[[0.1, 0.2], [0.3, 0.4]],
[[0.5, 0.6], [0.7, 0.8]],
[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]]
]
assert dto.b1 == [0.1, 0.9]
assert dto.T == 100
Expand All @@ -74,7 +72,7 @@ def test__str__(self) -> None:
observations=[0, 1],
cost_tensor=[[1, 2], [3, 4]],
observation_tensor=[[1, 2], [3, 4]],
transition_tensor=[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]],
transition_tensor=[[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]]],
b1=[0.1, 0.9],
T=100,
simulation_env_name="sim_env",
Expand All @@ -85,7 +83,7 @@ def test__str__(self) -> None:
"eta: 0.5, p_a: 0.8, p_c_1: 0.1, BTR: 10, negate_costs: True, seed: 123, "
"discount_factor: 0.9, states: [0, 1, 2], actions: [0, 1], observations: [[1, 2], [3, 4]], "
"cost_tensor: [[1, 2], [3, 4]], observation_tensor: [[1, 2], [3, 4]], "
"transition_tensor: [[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]], b1:[0.1, 0.9], "
"transition_tensor: [[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]]], b1:[0.1, 0.9], "
"T: 100, simulation_env_name: sim_env, gym_env_name: gym_env, max_horizon: 1000"
)
assert dto.__str__() == expected
Expand All @@ -107,7 +105,7 @@ def test_from_dict(self) -> None:
"observations": [0, 1],
"cost_tensor": [[1, 2], [3, 4]],
"observation_tensor": [[1, 2], [3, 4]],
"transition_tensor": [[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]],
"transition_tensor": [[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]]],
"b1": [0.1, 0.9],
"T": 100,
"simulation_env_name": "sim_env",
Expand All @@ -127,8 +125,7 @@ def test_from_dict(self) -> None:
assert dto.cost_tensor == [[1, 2], [3, 4]]
assert dto.observation_tensor == [[1, 2], [3, 4]]
assert dto.transition_tensor == [
[[0.1, 0.2], [0.3, 0.4]],
[[0.5, 0.6], [0.7, 0.8]],
[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]]
]
assert dto.b1 == [0.1, 0.9]
assert dto.T == 100
Expand All @@ -152,7 +149,7 @@ def test_to_dict(self) -> None:
observations=[0, 1],
cost_tensor=[[1, 2], [3, 4]],
observation_tensor=[[1, 2], [3, 4]],
transition_tensor=[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]],
transition_tensor=[[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]]],
b1=[0.1, 0.9],
T=100,
simulation_env_name="sim_env",
Expand All @@ -171,7 +168,7 @@ def test_to_dict(self) -> None:
"observations": [0, 1],
"cost_tensor": [[1, 2], [3, 4]],
"observation_tensor": [[1, 2], [3, 4]],
"transition_tensor": [[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]],
"transition_tensor": [[[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]]],
"b1": [0.1, 0.9],
"T": 100,
"simulation_env_name": "sim_env",
Expand All @@ -186,7 +183,7 @@ def test_from_json_file(self, mocker: pytest_mock.MockFixture) -> None:
eta = 2
p_a = 0.05
p_c_1 = 0.01
BTR = np.inf
BTR = 100
negate_costs = False
discount_factor = 1 - p_c_1
num_observations = 100
Expand Down Expand Up @@ -214,7 +211,7 @@ def test_from_json_file(self, mocker: pytest_mock.MockFixture) -> None:
eta=eta,
p_a=p_a,
p_c_1=p_c_1,
BTR=BTR,
BTR=100,
negate_costs=negate_costs,
seed=999,
discount_factor=discount_factor,
Expand All @@ -227,7 +224,7 @@ def test_from_json_file(self, mocker: pytest_mock.MockFixture) -> None:
observation_tensor=observation_tensor,
transition_tensor=transition_tensor,
b1=IntrusionRecoveryPomdpUtil.initial_belief(p_a=p_a),
T=BTR,
T=int(BTR),
simulation_env_name=simulation_name,
gym_env_name="csle-tolerance-intrusion-recovery-pomdp-v1",
)
Expand All @@ -238,7 +235,7 @@ def test_from_json_file(self, mocker: pytest_mock.MockFixture) -> None:
assert dto.eta == 2
assert dto.p_a == 0.05
assert dto.p_c_1 == 0.01
assert dto.BTR == np.inf
assert dto.BTR == 100
assert dto.negate_costs is False
assert dto.seed == 999
assert dto.discount_factor == 1 - p_c_1
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_from_json_file(self, mocker: pytest_mock.MockFixture) -> None:
p_c_1 = 0.01
p_c_2 = 0.01
p_u = 0.0
BTR = np.inf
BTR = 10
negate_costs = False
discount_factor = 1 - p_c_1
num_observations = 100
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_from_json_file(self, mocker: pytest_mock.MockFixture) -> None:
assert dto.p_c_1 == 0.01
assert dto.p_c_2 == 0.01
assert dto.p_u == 0.0
assert dto.BTR == np.inf
assert dto.BTR == BTR
assert dto.negate_costs is False
assert dto.seed == 999
assert dto.discount_factor == 1 - p_c_1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import csle_common.constants.constants as constants
import numpy as np
import pytest
from typing import Dict, Any


class TestInstrusionRecoveryPomdpEnvSuite:
Expand Down Expand Up @@ -153,7 +154,7 @@ def test_info(self) -> None:
gym_env_name="gym",
max_horizon=np.inf,
)
info = {}
info: Dict[str, Any] = {}
with pytest.raises(IndexError):
assert IntrusionRecoveryPomdpEnv(config)._info(info) is not None

Expand Down Expand Up @@ -247,7 +248,7 @@ def test_reset_traces(self) -> None:
gym_env_name="gym",
max_horizon=np.inf,
)
assert IntrusionRecoveryPomdpEnv(config).reset_traces() is None
assert not IntrusionRecoveryPomdpEnv(config).reset_traces()

@patch("time.time") # Mock the time.time function
@patch(
Expand Down
Loading

0 comments on commit caed7d0

Please sign in to comment.