xtest: pkcs11: Modify testcase 1011 for changes in C_Logout()

PKCS#11 specification states that :
When C_Logout successfully executes, any of the application’s
handles to private objects should become invalid (even if a user
is later logged back into the token, those handles remain invalid).
In addition, all private session objects from sessions belonging
to the application should also be destroyed.

One of the find sub-test case was expecting that after logging back
in a session , private session object would be visible which was
a wrong assumption. This has been modified.

Another subcase assumed the handle of the token object returned
would be same as that when the token object was created by that
session. This assumption would hold good only during the first
log in into this session. If a user logs out and then logs in
again, the token object handles would change. So this sub-case
has been moved to be tested during the first login to the session.

Signed-off-by: Ruchika Gupta <ruchika.gupta@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
diff --git a/host/xtest/pkcs11_1000.c b/host/xtest/pkcs11_1000.c
index d331dd8..6f2071e 100644
--- a/host/xtest/pkcs11_1000.c
+++ b/host/xtest/pkcs11_1000.c
@@ -2339,10 +2339,32 @@
 	if (!ADBG_EXPECT_CK_OK(c, rv))
 		goto out;
 
-	rv = C_Logout(session);
-	ADBG_EXPECT_CK_OK(c, rv);
+	Do_ADBG_EndSubCase(c, NULL);
 
-	logged_in = false;
+	/*
+	 * Sub test: finalize search without getting the handles found
+	 */
+	Do_ADBG_BeginSubCase(c, "Initiate and finalize straight a search");
+
+	rv = C_FindObjectsInit(session, find_template,
+			       ARRAY_SIZE(find_template));
+	if (!ADBG_EXPECT_CK_OK(c, rv))
+		goto out;
+
+	rv = C_FindObjectsFinal(session);
+	if (!ADBG_EXPECT_CK_OK(c, rv))
+		goto out;
+
+	/*
+	 * Check if object handles returned when creating objects with this
+	 * session are still valid
+	 */
+	for (i = 0; i < object_id; i++) {
+		rv = C_GetAttributeValue(session, obj_hdl[i], get_attr_template,
+					 ARRAY_SIZE(get_attr_template));
+		if (!ADBG_EXPECT_CK_OK(c, rv))
+			goto out;
+	}
 	Do_ADBG_EndSubCase(c, NULL);
 
 	/*
@@ -2351,6 +2373,11 @@
 	 */
 	Do_ADBG_BeginSubCase(c, "Find created Data objects when logged out");
 
+	rv = C_Logout(session);
+	ADBG_EXPECT_CK_OK(c, rv);
+
+	logged_in = false;
+
 	rv = test_find_objects(c, session, find_template,
 			       ARRAY_SIZE(find_template),
 			       obj_found, ARRAY_SIZE(obj_found), 2);
@@ -2439,37 +2466,10 @@
 
 	rv = test_find_objects(c, session, find_template,
 			       ARRAY_SIZE(find_template),
-			       obj_found, ARRAY_SIZE(obj_found), 4);
+			       obj_found, ARRAY_SIZE(obj_found), 3);
 	if (!ADBG_EXPECT_CK_OK(c, rv))
 		goto out;
 
-	Do_ADBG_EndSubCase(c, NULL);
-
-	/*
-	 * Sub test: finalize search without getting the handles found
-	 */
-	Do_ADBG_BeginSubCase(c, "Initiate and finalize straight a search");
-
-	rv = C_FindObjectsInit(session, find_template,
-			       ARRAY_SIZE(find_template));
-	if (!ADBG_EXPECT_CK_OK(c, rv))
-		goto out;
-
-	rv = C_FindObjectsFinal(session);
-	if (!ADBG_EXPECT_CK_OK(c, rv))
-		goto out;
-
-	/*
-	 * Check if object handles returned when creating objects with this
-	 * session are still valid
-	 */
-	for (i = 0; i < object_id; i++) {
-		rv = C_GetAttributeValue(session, obj_hdl[i], get_attr_template,
-					 ARRAY_SIZE(get_attr_template));
-		if (!ADBG_EXPECT_CK_OK(c, rv))
-			goto out;
-	}
-
 	rv = C_Logout(session);
 	ADBG_EXPECT_CK_OK(c, rv);