kunit: mock : Retire expectations on saturation when they are passed to the InSequence macro.

Change-Id: I22b047cb99cc3b76b153c2ab325e0108f930509d
Google-Bug-Id: 115674831
Signed-off-by: Harshal Tushar Lehri <halehri@google.com>
diff --git a/test/mock-test.c b/test/mock-test.c
index b2abadb..7a6ce3b 100644
--- a/test/mock-test.c
+++ b/test/mock-test.c
@@ -578,6 +578,38 @@
 	mock->do_expect(mock, "c", mock_stub, param_type, c_params, param_len);
 }
 
+static void mock_test_in_sequence_retire_on_saturation(struct test *test)
+{
+	struct mock_test_context *ctx = test->priv;
+	struct MOCK(test) *mock_test = ctx->mock_test;
+	struct test *trgt = mock_get_trgt(mock_test);
+	struct mock *mock = ctx->mock;
+
+	struct mock_param_matcher *a_matchers[] = { int_eq(trgt, 1) };
+	struct mock_param_matcher *b_matchers[] = { int_eq(trgt, 2) };
+	struct mock_param_matcher *c_matchers[] = { int_eq(trgt, 3) };
+
+	struct mock_expectation *c = mock_add_matcher(mock, "c", mock_stub,
+                c_matchers, param_len);
+	struct mock_expectation *b = mock_add_matcher(mock, "b", mock_stub,
+                b_matchers, param_len);
+	struct mock_expectation *a_1 = mock_add_matcher(mock, "a", mock_stub,
+                a_matchers, param_len);
+        struct mock_expectation *a_2 = mock_add_matcher(mock, "a", mock_stub,
+                a_matchers, param_len);
+
+	InSequence(test, a_1, b, a_2, c);
+
+	Never(EXPECT_CALL(fail(mock_get_ctrl(mock_test), any(test))));
+
+        mock->do_expect(mock, "a", mock_stub, param_type, a_params, param_len);
+	mock->do_expect(mock, "b", mock_stub, param_type, b_params, param_len);
+        mock->do_expect(mock, "a", mock_stub, param_type, a_params, param_len);
+	mock->do_expect(mock, "c", mock_stub, param_type, c_params, param_len);
+
+        mock_validate_expectations(mock);
+}
+
 void *do_mocked_fail(struct mock_action *this, const void **params, int len)
 {
 	static const int ret;
@@ -639,6 +671,7 @@
 	TEST_CASE(mock_test_in_sequence_abc_success),
 	TEST_CASE(mock_test_in_sequence_bac_success),
 	TEST_CASE(mock_test_in_sequence_no_a_fail),
+        TEST_CASE(mock_test_in_sequence_retire_on_saturation),
 	{},
 };
 
diff --git a/test/mock.c b/test/mock.c
index 4f2a006..7dc9576 100644
--- a/test/mock.c
+++ b/test/mock.c
@@ -392,7 +392,10 @@
 
 	va_start(args, first);
 
+        RetireOnSaturation(first);
+
 	while ((curr = va_arg(args, struct mock_expectation*))) {
+                RetireOnSaturation(curr);
 		entry = test_kzalloc(test, sizeof(*entry), GFP_KERNEL);
 		if (!entry) {
 			va_end(args);