stp: fix TC_rkm_unreg_active

Create the routing key dynamically, before trying to unregister it, so
osmo-stp doesn't answer with ERR_NOT_REG instead of the expected
ERR_ASP_ACTIVE. While at it, add missing clean up logic.

Related: OS#4239
Change-Id: I31fcba85d23a8767eb0ceb513ff5b440558a475b
diff --git a/stp/STP_Tests_M3UA.ttcn b/stp/STP_Tests_M3UA.ttcn
index 0bc398d..13703d0 100644
--- a/stp/STP_Tests_M3UA.ttcn
+++ b/stp/STP_Tests_M3UA.ttcn
@@ -637,9 +637,11 @@
 
 /* try to de-register a routing key for an active ASP -> ERROR */
 testcase TC_rkm_unreg_active() runs on RAW_M3UA_CT {
-	var OCT3 dpc := int2oct(mp_m3ua_configs[0].point_code, 3); // must match config
-	var OCT4 rctx := int2oct(mp_m3ua_configs[0].routing_ctx, 4);  // must match config
+	var OCT3 dpc := int2oct(123, 3);
+	var OCT4 rctx := int2oct(1234, 4);
 
+	f_init_common();
+	f_vty_config2(VTY, {"cs7 instance 0"}, "xua rkm routing-key-allocation dynamic-permitted");
 	f_init_m3ua();
 
 	/* first register the routing key */
@@ -647,12 +649,22 @@
 
 	/* then activate the ASP */
 	f_M3UA_asp_up_act(0);
+	f_M3UA_exp(0, tr_M3UA_DAVA({*}, rctx));
+	f_M3UA_exp(0, tr_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, c_M3UA_ST_I_AS_ACTIVE, *));
+	f_M3UA_exp(0, tr_M3UA_DAVA({*}, *));
 
-	/* then try to de-regsiter */
+	/* then try to de-register -> ERR_ASP_ACTIVE */
 	f_M3UA_send(0, ts_M3UA_DEREG_REQ(ts_M3UA_routing_ctx(rctx)));
 	f_M3UA_exp(0, tr_M3UA_DEREG_RSP({tr_M3UA_dereg_res(?,c_m3UA_DEREGSTS_ERR_ASP_ACTIVE)}));
-	/* FIXME: we now may have changed the state on the STP side! */
 
+	/* deactivate ASP and properly de-register to clean up */
+	f_M3UA_asp_inact(0);
+	f_M3UA_send(0, ts_M3UA_DEREG_REQ(ts_M3UA_routing_ctx(rctx)));
+	f_M3UA_exp(0, tr_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, c_M3UA_ST_I_AS_PENDING, *));
+	f_M3UA_exp(0, tr_M3UA_NOTIFY(c_M3UA_ST_T_STATE_CHG, c_M3UA_ST_I_AS_PENDING, *));
+	f_M3UA_exp(0, tr_M3UA_DEREG_RSP({tr_M3UA_dereg_res(?,c_m3UA_DEREGSTS_SUCCESS)}));
+
+	f_vty_config2(VTY, {"cs7 instance 0"}, "xua rkm routing-key-allocation static-only");
 	f_clear_m3ua();
 }