diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2021-08-24 15:50:19 +0000 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2021-09-22 15:40:02 +0200 |
| commit | a7ce77be27d8e3728b97122a005bc5b23298cfc3 (patch) | |
| tree | 1f3adbdd7719ec9c6bf7eb4d48f308004410f775 /prog/encoding_test.go | |
| parent | 041a868956e51efc0dace9e3dff874332a8cdccc (diff) | |
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.
Diffstat (limited to 'prog/encoding_test.go')
| -rw-r--r-- | prog/encoding_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
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(` |
