kernel/uevent: Adjust the number of uevents dynamically in uevent02
PATCH 1/1 kernel/uevent: Adjust the number of uevents dynamically in uevent02
When CONFIG_SMP is not selected, CONFIG_RPS will not be enabled. Causes the kernel to not create rx queues in sysfs[*1] when creating tun devices. uevent02 will check if the rx queue exists, so we have to dynamically adjust the number of uevents to pass this testcase.
--- testcases/kernel/uevents/uevent02.c | 146 ++++++++++++++-------------- 1 file changed, 73 insertions(+), 73 deletions(-)
testcases/kernel/uevents/uevent02.c +73 -73
@@ -19,11 +19,71 @@#include <linux/if_tun.h> #include "tst_test.h" +#include "tst_private.h" #include "uevent.h" #define TUN_PATH "/dev/net/tun" +#define MAX_UEVENT 7 + +struct uevent_desc add = { + .msg ="add@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; +struct uevent_desc add_rx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc add_tx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_rx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_tx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem = { + .msg ="remove@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; +static void generate_tun_uevents (void ) {int fd =SAFE_OPEN (TUN_PATH ,O_RDWR );
@@ -42,79 +102,19 @@ static void generate_tun_uevents(void)static void verify_uevent (void ) { -int pid, fd; - -struct uevent_desc add = { - .msg ="add@/devices/virtual/net/ltp-tun0" , - .value_cnt =4 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0" , -"SUBSYSTEM=net" , -"INTERFACE=ltp-tun0" , - } - }; - -struct uevent_desc add_rx = { - .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc add_tx = { - .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem_rx = { - .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem_tx = { - .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem = { - .msg ="remove@/devices/virtual/net/ltp-tun0" , - .value_cnt =4 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0" , -"SUBSYSTEM=net" , -"INTERFACE=ltp-tun0" , - } - }; - -const struct uevent_desc *const uevents[] = { - &add, - &add_rx, - &add_tx, - &rem_rx, - &rem_tx, - &rem, -NULL - }; +const struct uevent_desc *uevents[MAX_UEVENT ]; +int pid, fd, i =0 ; +int has_RPS =tst_kconfig_get ("CONFIG_RPS" ); + + uevents[i++] = &add; +if (has_RPS) + uevents[i++] = &add_rx; + uevents[i++] = &add_tx; +if (has_RPS) + uevents[i++] = &rem_rx; + uevents[i++] = &rem_tx; + uevents[i++] = &rem; + uevents[i++] =NULL ; pid =SAFE_FORK ();if (!pid) {
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 10 lines
Signed-off-by Dylan Jhong <[email protected]>--- testcases/kernel/uevents/uevent02.c | 146 ++++++++++++++-------------- 1 file changed, 73 insertions(+), 73 deletions(-)testcases/kernel/uevents/uevent02.c +0
-0
testcases/kernel/uevents/uevent02.c line 22
Quoted 4 lines
testcases/kernel/uevents/uevent02.c +1
-0@@ -19,11 +19,71 @@#include <linux/if_tun.h> #include "tst_test.h" +#include "tst_private.h"
This header is called private for a reason, the tst_kconfig_get() is not meant to be used from tests, you are supposed to call tst_config_read() as it's done in shmget02.c for example.
Quoted 52 lines
testcases/kernel/uevents/uevent02.c +48
-0#include "uevent.h" #define TUN_PATH "/dev/net/tun" +#define MAX_UEVENT 7 + +struct uevent_desc add = { + .msg ="add@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; +struct uevent_desc add_rx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc add_tx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_rx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_tx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +};
testcases/kernel/uevents/uevent02.c line 85
Quoted 10 lines
testcases/kernel/uevents/uevent02.c +10
-0+struct uevent_desc rem = { + .msg ="remove@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +};
Why do we have to move these outside of the function? I do not see a single reason to do so.
testcases/kernel/uevents/uevent02.c static void generate_tun_uevents(void) · line 107
Quoted 3 lines
testcases/kernel/uevents/uevent02.c +3
-0+const struct uevent_desc *uevents[MAX_UEVENT ]; +int pid, fd, i =0 ; +int has_RPS =tst_kconfig_get ("CONFIG_RPS" );
Getting the flag should be done once in the test setup, otherwise kernel config will be parsed in each iteration of the test.
Quoted 9 lines
testcases/kernel/uevents/uevent02.c +9
-0+ uevents[i++] = &add; +if (has_RPS) + uevents[i++] = &add_rx; + uevents[i++] = &add_tx; +if (has_RPS) + uevents[i++] = &rem_rx; + uevents[i++] = &rem_tx; + uevents[i++] = &rem; + uevents[i++] =NULL ;
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
On Thu, Sep 15, 2022 at 04:58:56PM +0800, Cyril Hrubis wrote:
Hi Cyril,
Thanks for reviewing this patch.
Quoted 13 lines
Hi!
Quoted 12 lines
Signed-off-by Dylan Jhong <[email protected]>--- testcases/kernel/uevents/uevent02.c | 146 ++++++++++++++-------------- 1 file changed, 73 insertions(+), 73 deletions(-)testcases/kernel/uevents/uevent02.c +0
-0@@ -19,11 +19,71 @@#include <linux/if_tun.h>
Quoted 7 lines
testcases/kernel/uevents/uevent02.c line 22
Quoted 2 lines
testcases/kernel/uevents/uevent02.c +1
-0#include "tst_test.h" +#include "tst_private.h" This header is called private for a reason, the
tst_kconfig_get()is not meant to be used from tests, you are supposed to calltst_config_read()as it's done inshmget02.cfor example.
Thanks. I will fix this in v2 patch.
Quoted 57 lines
Quoted 57 lines
testcases/kernel/uevents/uevent02.c +53
-0#include "uevent.h" #define TUN_PATH "/dev/net/tun" +#define MAX_UEVENT 7 + +struct uevent_desc add = { + .msg ="add@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; +struct uevent_desc add_rx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc add_tx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_rx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_tx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem = { + .msg ="remove@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=remove" ,
Quoted 9 lines
testcases/kernel/uevents/uevent02.c line 39
Quoted 5 lines
testcases/kernel/uevents/uevent02.c +5
-0+ "DEVPATH=/devices/virtual/net/ltp-tun0", + "SUBSYSTEM=net", + "INTERFACE=ltp-tun0", + } +};Why do we have to move these outside of the function? I do not see a single reason to do so.
I think separating the declaration of uevents and dynamic adding uevents will make the program easier to read.
This part is open to discussion, I'm just giving my thoughts. if everyone think it's a bad idea, I'll change it back in v2 patch.
declaration
----------------------------
struct uevent_desc rem_tx = {}
struct uevent_desc add_rx = {}
struct uevent_desc add_tx = {}
.....
dynamically adding uevent:
--------------------------
uevents[i++] = &add;
if (has_RPS)
uevents[i++] = &add_rx;
uevents[i++] = &add_tx;
if (has_RPS)
uevents[i++] = &rem_rx;uevents[i++] = &rem_tx;
uevents[i++] = &rem;
uevents[i++] = NULL;
Quoted 7 lines
testcases/kernel/uevents/uevent02.c static void generate_tun_uevents(void) · line 107
Quoted 3 lines
testcases/kernel/uevents/uevent02.c +3
-0+const struct uevent_desc *uevents[MAX_UEVENT ]; +int pid, fd, i =0 ; +int has_RPS =tst_kconfig_get ("CONFIG_RPS" );Getting the flag should be done once in the test setup, otherwise kernel config will be parsed in each iteration of the test.
If we parse the kernel configuration during test setup, we will block all images without CONFIG_RPS from executing this testcase. This is not my intention, in this patch I designed to continue executing uevent02 even without CONFIG_RPS. Just adjusting uevents can pass this test. So I think parsing the kernel config in test_all() should be the correct way.
Best,
Dylan
Quoted 15 lines
Quoted 9 lines
testcases/kernel/uevents/uevent02.c +9
-0+ uevents[i++] = &add; +if (has_RPS) + uevents[i++] = &add_rx; + uevents[i++] = &add_tx; +if (has_RPS) + uevents[i++] = &rem_rx; + uevents[i++] = &rem_tx; + uevents[i++] = &rem; + uevents[i++] =NULL ;Signature · 2 lines
Cyril Hrubis [email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 99 lines
Quoted 57 lines
Quoted 57 lines
#include "
uevent.h"#define
TUN_PATH"/dev/net/tun"testcases/kernel/uevents/uevent02.c +53
-0+#define MAX_UEVENT 7 + +struct uevent_desc add = { + .msg ="add@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; +struct uevent_desc add_rx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc add_tx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_rx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_tx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem = { + .msg ="remove@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=remove" ,Quoted 9 lines
testcases/kernel/uevents/uevent02.c line 39
Quoted 5 lines
testcases/kernel/uevents/uevent02.c +5
-0+ "DEVPATH=/devices/virtual/net/ltp-tun0", + "SUBSYSTEM=net", + "INTERFACE=ltp-tun0", + } +};Why do we have to move these outside of the function? I do not see a single reason to do so.
I think separating the declaration of uevents and dynamic adding uevents will make the program easier to read.
This part is open to discussion, I'm just giving my thoughts. if everyone think it's a bad idea, I'll change it back in v2 patch.declaration
----------------------------
structuevent_descrem_tx= {}
structuevent_descadd_rx= {}
structuevent_descadd_tx= {}
.....dynamically adding uevent:
--------------------------
uevents[i++] = &add;
if (has_RPS)uevents[i++] = &add_rx; uevents[i++] = &add_tx; if (has_RPS) uevents[i++] = &rem_rx;uevents[i++] =
&rem_tx;
uevents[i++] = &rem;
uevents[i++] = NULL;Quoted 7 lines
testcases/kernel/uevents/uevent02.c static void generate_tun_uevents(void) · line 107
Quoted 3 lines
testcases/kernel/uevents/uevent02.c +3
-0+const struct uevent_desc *uevents[MAX_UEVENT ]; +int pid, fd, i =0 ; +int has_RPS =tst_kconfig_get ("CONFIG_RPS" );Getting the flag should be done once in the test setup, otherwise kernel config will be parsed in each iteration of the test.
Quoted 5 lines
If we parse the kernel configuration during test setup, we will block all images without
CONFIG_RPSfrom executing this testcase. This is not my intention, in this patch I designed to continue executing uevent02 even withoutCONFIG_RPS. Just adjusting uevents can pass this test. So I think parsing the kernel config intest_all()should be the correct way.
I do not think that we understand each other here. What I proposed is to call the function that parses kernel config in the test setup and initialize the has_RPS flag there so that it's not called on each interation of the run() function (e.g. when test is passed -i 100 on command line).
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
Oh, i got it!!! Sorry for the misunderstanding.
I thought this was talking about adding the .needs_kconfigs property. I will add setup() function in v2 patch.
And about the adjustment of uevent declaration, any comments that I can do in v2 patch?
Best,
Dylan
Quoted 115 lines · Cyril Hrubis
Hi!
Quoted 99 lines
Quoted 57 lines
Quoted 57 lines
#include "
uevent.h"#define
TUN_PATH"/dev/net/tun"testcases/kernel/uevents/uevent02.c +53
-0+#define MAX_UEVENT 7 + +struct uevent_desc add = { + .msg ="add@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; +struct uevent_desc add_rx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc add_tx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_rx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem_tx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; +struct uevent_desc rem = { + .msg ="remove@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=remove" ,Quoted 9 lines
testcases/kernel/uevents/uevent02.c line 39
Quoted 5 lines
testcases/kernel/uevents/uevent02.c +5
-0+ "DEVPATH=/devices/virtual/net/ltp-tun0", + "SUBSYSTEM=net", + "INTERFACE=ltp-tun0", + } +};Why do we have to move these outside of the function? I do not see a single reason to do so.
I think separating the declaration of uevents and dynamic adding uevents will make the program easier to read.
This part is open to discussion, I'm just giving my thoughts. if everyone think it's a bad idea, I'll change it back in v2 patch.declaration
----------------------------
structuevent_descrem_tx= {}
structuevent_descadd_rx= {}
structuevent_descadd_tx= {}
.....dynamically adding uevent:
--------------------------
uevents[i++] = &add;
if (has_RPS)uevents[i++] = &add_rx; uevents[i++] = &add_tx; if (has_RPS) uevents[i++] = &rem_rx;uevents[i++] =
&rem_tx;
uevents[i++] = &rem;
uevents[i++] = NULL;Quoted 7 lines
testcases/kernel/uevents/uevent02.c static void generate_tun_uevents(void) · line 107
Quoted 3 lines
testcases/kernel/uevents/uevent02.c +3
-0+const struct uevent_desc *uevents[MAX_UEVENT ]; +int pid, fd, i =0 ; +int has_RPS =tst_kconfig_get ("CONFIG_RPS" );Getting the flag should be done once in the test setup, otherwise kernel config will be parsed in each iteration of the test.
Quoted 5 lines
If we parse the kernel configuration during test setup, we will block all images without
CONFIG_RPSfrom executing this testcase. This is not my intention, in this patch I designed to continue executing uevent02 even withoutCONFIG_RPS. Just adjusting uevents can pass this test. So I think parsing the kernel config intest_all()should be the correct way.I do not think that we understand each other here. What I proposed is to call the function that parses kernel config in the test setup and initialize the
has_RPSflag there so that it's not called on each interation of therun()function (e.g. when test is passed -i 100 on command line).Signature · 2 lines
Cyril Hrubis [email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 6 lines
Oh, i got it!!! Sorry for the misunderstanding.
I thought this was talking about adding the .needs_kconfigs property. I will addsetup()function in v2 patch.And about the adjustment of uevent declaration, any comments that I can do in v2 patch?
I would avoid any unnecessary changes.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp