1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci// Copyright (c) 2021 SUSE LLC <rpalethorpe@suse.com> 3f08c3bdfSopenharmony_ci 4f08c3bdfSopenharmony_ci// Find and fix violations of rule LTP-002 5f08c3bdfSopenharmony_ci 6f08c3bdfSopenharmony_ci// Set with -D fix 7f08c3bdfSopenharmony_civirtual fix 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci// Find all positions where TEST is _used_. 10f08c3bdfSopenharmony_ci@ depends on !fix exists @ 11f08c3bdfSopenharmony_ci@@ 12f08c3bdfSopenharmony_ci 13f08c3bdfSopenharmony_ci* TEST(...); 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_ci// Below are rules which will create a patch to replace TEST usage 16f08c3bdfSopenharmony_ci// It assumes we can use the ret var without conflicts 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci// Fix all references to the variables TEST modifies when they occur in a 19f08c3bdfSopenharmony_ci// function where TEST was used. 20f08c3bdfSopenharmony_ci@ depends on fix exists @ 21f08c3bdfSopenharmony_ci@@ 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_ci TEST(...) 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci <... 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci( 28f08c3bdfSopenharmony_ci- TST_RET 29f08c3bdfSopenharmony_ci+ ret 30f08c3bdfSopenharmony_ci| 31f08c3bdfSopenharmony_ci- TST_ERR 32f08c3bdfSopenharmony_ci+ errno 33f08c3bdfSopenharmony_ci| 34f08c3bdfSopenharmony_ci- TTERRNO 35f08c3bdfSopenharmony_ci+ TERRNO 36f08c3bdfSopenharmony_ci) 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_ci ...> 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ci// Replace TEST in all functions where it occurs only at the start. It 41f08c3bdfSopenharmony_ci// is slightly complicated by adding a newline if a statement appears 42f08c3bdfSopenharmony_ci// on the line after TEST(). It is not clear to me what the rules are 43f08c3bdfSopenharmony_ci// for matching whitespace as it has no semantic meaning, but this 44f08c3bdfSopenharmony_ci// appears to work. 45f08c3bdfSopenharmony_ci@ depends on fix @ 46f08c3bdfSopenharmony_ciidentifier fn; 47f08c3bdfSopenharmony_ciexpression tested_expr; 48f08c3bdfSopenharmony_cistatement st; 49f08c3bdfSopenharmony_ci@@ 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_ci fn (...) 52f08c3bdfSopenharmony_ci { 53f08c3bdfSopenharmony_ci- TEST(tested_expr); 54f08c3bdfSopenharmony_ci+ const long ret = tested_expr; 55f08c3bdfSopenharmony_ci( 56f08c3bdfSopenharmony_ci+ 57f08c3bdfSopenharmony_ci st 58f08c3bdfSopenharmony_ci| 59f08c3bdfSopenharmony_ci 60f08c3bdfSopenharmony_ci) 61f08c3bdfSopenharmony_ci ... when != TEST(...) 62f08c3bdfSopenharmony_ci } 63f08c3bdfSopenharmony_ci 64f08c3bdfSopenharmony_ci// Replace TEST in all functions where it occurs at the start 65f08c3bdfSopenharmony_ci// Functions where it *only* occurs at the start were handled above 66f08c3bdfSopenharmony_ci@ depends on fix @ 67f08c3bdfSopenharmony_ciidentifier fn; 68f08c3bdfSopenharmony_ciexpression tested_expr; 69f08c3bdfSopenharmony_cistatement st; 70f08c3bdfSopenharmony_ci@@ 71f08c3bdfSopenharmony_ci 72f08c3bdfSopenharmony_ci fn (...) 73f08c3bdfSopenharmony_ci { 74f08c3bdfSopenharmony_ci- TEST(tested_expr); 75f08c3bdfSopenharmony_ci+ long ret = tested_expr; 76f08c3bdfSopenharmony_ci( 77f08c3bdfSopenharmony_ci+ 78f08c3bdfSopenharmony_ci st 79f08c3bdfSopenharmony_ci| 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_ci) 82f08c3bdfSopenharmony_ci ... 83f08c3bdfSopenharmony_ci } 84f08c3bdfSopenharmony_ci 85f08c3bdfSopenharmony_ci// Add ret var at the start of a function where TEST occurs and there 86f08c3bdfSopenharmony_ci// is not already a ret declaration 87f08c3bdfSopenharmony_ci@ depends on fix exists @ 88f08c3bdfSopenharmony_ciidentifier fn; 89f08c3bdfSopenharmony_ci@@ 90f08c3bdfSopenharmony_ci 91f08c3bdfSopenharmony_ci fn (...) 92f08c3bdfSopenharmony_ci { 93f08c3bdfSopenharmony_ci+ long ret; 94f08c3bdfSopenharmony_ci ... when != long ret; 95f08c3bdfSopenharmony_ci 96f08c3bdfSopenharmony_ci TEST(...) 97f08c3bdfSopenharmony_ci ... 98f08c3bdfSopenharmony_ci } 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci// Replace any remaining occurrences of TEST 101f08c3bdfSopenharmony_ci@ depends on fix @ 102f08c3bdfSopenharmony_ciexpression tested_expr; 103f08c3bdfSopenharmony_ci@@ 104f08c3bdfSopenharmony_ci 105f08c3bdfSopenharmony_ci- TEST(tested_expr); 106f08c3bdfSopenharmony_ci+ ret = tested_expr; 107f08c3bdfSopenharmony_ci 108