test: add python script for windows cases to replace the bat (#30386)
* test: add python scripts for test windows cases replace the old bat scripts * refactor: update color_echo function to use log_file instead of error_file * ci: update workflow to use fixed branch for Windows test runs * chore: add empty line for better readability in tdengine-test.yml * test:fix from branch fix/xftan/taos-shell-configdir * fix: replace global variant configDir with local variant on taos * fix: remove check cfgdir exist * fix: restore no input msg * fix: move dumpConfig after taos_options * fix: dump Config on windows failed * fix: move configDirShell variant to shellArgument.c * fix: get last char pos is -1 * ci: update Windows test workflow to use main branch and enhance test output * ci: remove unnecessary line from tdengine-test workflow --------- Co-authored-by: Alex Duan <417921451@qq.com>
This commit is contained in:
parent
af06bea439
commit
55c5f8190d
|
@ -543,7 +543,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *input
|
|||
char cfgFile[PATH_MAX + 100] = {0};
|
||||
|
||||
TAOS_CHECK_RETURN(taosExpandDir(inputCfgDir, cfgDir, PATH_MAX));
|
||||
char lastC = cfgDir[strlen(cfgDir) - 1];
|
||||
int32_t pos = strlen(cfgDir);
|
||||
if(pos > 0) {
|
||||
pos -= 1;
|
||||
}
|
||||
char lastC = cfgDir[pos];
|
||||
char *tdDirsep = TD_DIRSEP;
|
||||
if (lastC == '\\' || lastC == '/') {
|
||||
tdDirsep = "";
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
import os
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
def get_time_seconds():
|
||||
current_time = time.strftime("%H:%M:%S", time.localtime())
|
||||
hh, mm, ss = map(int, current_time.split(':'))
|
||||
return (hh * 60 + mm) * 60 + ss
|
||||
|
||||
def color_echo(color, message, time1, log_file=None):
|
||||
current_time = time.strftime("%H:%M:%S", time.localtime())
|
||||
time2 = get_time_seconds()
|
||||
inter_time = time2 - time1
|
||||
print(f"End at {current_time} , cast {inter_time}s")
|
||||
print(message)
|
||||
if log_file:
|
||||
with open(log_file, 'r') as file:
|
||||
print(file.read())
|
||||
|
||||
def check_skip_case(line):
|
||||
skip_case = False
|
||||
if line == "python3 ./test.py -f 1-insert/insertWithMoreVgroup.py":
|
||||
skip_case = False
|
||||
elif line == "python3 ./test.py -f 2-query/queryQnode.py":
|
||||
skip_case = False
|
||||
elif "-R" in line:
|
||||
skip_case = True
|
||||
return skip_case
|
||||
|
||||
def run_tests(case_file):
|
||||
exit_num = 0
|
||||
a = 0
|
||||
failed_tests = []
|
||||
|
||||
with open(case_file, 'r') as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
if check_skip_case(line):
|
||||
continue
|
||||
|
||||
if line.startswith("python3"):
|
||||
a += 1
|
||||
print(f"{a} Processing {line}")
|
||||
time1 = get_time_seconds()
|
||||
print(f"Start at {time.strftime('%H:%M:%S', time.localtime())}")
|
||||
|
||||
log_file = f"log_{a}.txt"
|
||||
with open(log_file, 'w') as log:
|
||||
process = subprocess.run(line.split(), stdout=log, stderr=log)
|
||||
if process.returncode != 0:
|
||||
color_echo("0c", "failed", time1, log_file)
|
||||
exit_num = 8
|
||||
failed_tests.append(line)
|
||||
else:
|
||||
color_echo("0a", "Success", time1)
|
||||
|
||||
if failed_tests:
|
||||
with open("failed.txt", 'w') as file:
|
||||
for test in failed_tests:
|
||||
file.write(test + '\n')
|
||||
|
||||
return exit_num
|
||||
|
||||
if __name__ == "__main__":
|
||||
case_file = "simpletest.bat"
|
||||
if len(os.sys.argv) > 1 and os.sys.argv[1] == "full":
|
||||
case_file = "fulltest.sh"
|
||||
if len(os.sys.argv) > 2:
|
||||
case_file = os.sys.argv[2]
|
||||
|
||||
exit_code = run_tests(case_file)
|
||||
print(f"Final exit code: {exit_code}")
|
||||
if exit_code != 0:
|
||||
print("One or more tests failed.")
|
||||
os.sys.exit(exit_code)
|
|
@ -145,5 +145,6 @@ void shellTestNetWork();
|
|||
|
||||
// shellMain.c
|
||||
extern SShellObj shell;
|
||||
extern char configDirShell[PATH_MAX];
|
||||
|
||||
#endif /*_TD_SHELL_INT_H_*/
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "shellInt.h"
|
||||
#include "../../inc/pub.h"
|
||||
|
||||
char configDirShell[PATH_MAX] = {0};
|
||||
|
||||
#define TAOS_CONSOLE_PROMPT_CONTINUE " -> "
|
||||
|
||||
|
@ -381,9 +381,16 @@ static int32_t shellCheckArgs() {
|
|||
printf("Invalid cfgdir:%s\r\n", pArgs->cfgdir);
|
||||
return -1;
|
||||
} else {
|
||||
if (taosExpandDir(pArgs->cfgdir, configDir, PATH_MAX) != 0) {
|
||||
tstrncpy(configDir, pArgs->cfgdir, PATH_MAX);
|
||||
if (taosExpandDir(pArgs->cfgdir, configDirShell, PATH_MAX) != 0) {
|
||||
tstrncpy(configDirShell, pArgs->cfgdir, PATH_MAX);
|
||||
}
|
||||
// check cfg dir exist
|
||||
/*
|
||||
if(!taosIsDir(configDirShell)) {
|
||||
printf("folder not exist. cfgdir:%s expand:%s\r\n", pArgs->cfgdir, configDirShell);
|
||||
configDirShell[0] = 0;
|
||||
return -1;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ void initArgument(SShellArgs *pArgs) {
|
|||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int code = 0;
|
||||
#if !defined(WINDOWS)
|
||||
taosSetSignal(SIGBUS, shellCrashHandler);
|
||||
#endif
|
||||
|
@ -92,19 +93,34 @@ int main(int argc, char *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (shell.args.is_dump_config) {
|
||||
shellDumpConfig();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (getDsnEnv() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// first taos_option(TSDB_OPTION_DRIVER ...) no load driver
|
||||
if (setConnMode(shell.args.connMode, shell.args.dsn, false)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// second taos_option(TSDB_OPTION_CONFIGDIR ...) set configDir global
|
||||
if (configDirShell[0] != 0) {
|
||||
code = taos_options(TSDB_OPTION_CONFIGDIR, configDirShell);
|
||||
if (code) {
|
||||
fprintf(stderr, "failed to set config dir:%s code:[0x%08X]\r\n", configDirShell, code);
|
||||
return -1;
|
||||
}
|
||||
//printf("Load with input config dir:%s\n", configDirShell);
|
||||
}
|
||||
|
||||
#ifndef TD_ASTRA
|
||||
// dump config
|
||||
if (shell.args.is_dump_config) {
|
||||
shellDumpConfig();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// taos_init
|
||||
if (taos_init() != 0) {
|
||||
fprintf(stderr, "failed to init shell since %s [0x%08X]\r\n", taos_errstr(NULL), taos_errno(NULL));
|
||||
return -1;
|
||||
|
@ -114,12 +130,6 @@ int main(int argc, char *argv[]) {
|
|||
taos_set_hb_quit(1);
|
||||
|
||||
#ifndef TD_ASTRA
|
||||
if (shell.args.is_dump_config) {
|
||||
shellDumpConfig();
|
||||
taos_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (shell.args.is_startup || shell.args.is_check) {
|
||||
shellCheckServerStatus();
|
||||
taos_cleanup();
|
||||
|
|
|
@ -80,7 +80,7 @@ void shellGenerateAuth() {
|
|||
void shellDumpConfig() {
|
||||
(void)osDefaultInit();
|
||||
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
if (taosInitCfg(configDirShell, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
fprintf(stderr, "failed to load cfg since %s [0x%08X]\n", terrstr(), terrno);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue