From a7ce77be27d8e3728b97122a005bc5b23298cfc3 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 24 Aug 2021 15:50:19 +0000 Subject: all: introduce call properties Call properties let us specify how each individual call within a program must be executed. So far the only way to enforce extra rules was to pass extra program-level properties (e.g. that is how fault injection was done). However, it entangles the logic and not flexible enough. Implement an ability to pass properties along with each individual call. --- prog/encoding_test.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'prog/encoding_test.go') diff --git a/prog/encoding_test.go b/prog/encoding_test.go index 4ba9edd50..d7171248f 100644 --- a/prog/encoding_test.go +++ b/prog/encoding_test.go @@ -312,6 +312,21 @@ func TestDeserialize(t *testing.T) { Out: `test$opt2(0x0)`, StrictErr: `non-nil argument for nil type`, }, + { + In: `test$opt2(0x0) (non_existing_prop: 123)`, + Out: `test$opt2(0x0)`, + StrictErr: `unknown call property: non_existing_prop`, + }, + { + In: `test$opt2(0x0) (fail_nth: zzz)`, + Out: `test$opt2(0x0)`, + StrictErr: `invalid int value: zzz`, + }, + { + In: `test$opt2(0x0) (non_existing_prop: 123, fail_nth: 1)`, + Out: `test$opt2(0x0) (fail_nth: 1)`, + StrictErr: `unknown call property: non_existing_prop`, + }, }) } @@ -384,6 +399,52 @@ func testSerializeDeserialize(t *testing.T, p0 *Prog, data0, data1 []byte) (bool return true, 0, 0 } +func TestSerializeCallProps(t *testing.T) { + target := initTargetTest(t, "test", "64") + type SerializeCallPropsTest struct { + prog string + props []CallProps + } + + tests := []SerializeCallPropsTest{ + { + "serialize0(0x0)\n", + []CallProps{DefaultCallProps()}, + }, + { + "serialize0(0x0) ()\n", + []CallProps{DefaultCallProps()}, + }, + { + "serialize0(0x0) (fail_nth: 5)\n", + []CallProps{{5}}, + }, + { + "serialize0(0x0) (fail_nth)\n", + nil, + }, + { + "serialize0(0x0) (fail_nth: \"5\")\n", + nil, + }, + } + + for _, test := range tests { + p, err := target.Deserialize([]byte(test.prog), Strict) + if test.props != nil && err != nil { + t.Fatal(err) + } else if test.props == nil && err == nil { + t.Errorf("expected an error, but got none\n%s", test.prog) + } + + for i, props := range test.props { + if !reflect.DeepEqual(props, p.Calls[i].Props) { + t.Errorf("%v-th call props differ: %v != %v", i, props, p.Calls[i].Props) + } + } + } +} + func TestDeserializeComments(t *testing.T) { target := initTargetTest(t, "test", "64") p, err := target.Deserialize([]byte(` -- cgit mrf-deployment