From 7db1a851300d497d4ab5067796fba287cff3d5d4 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 31 Mar 2014 17:42:14 +0000 Subject: [PATCH] .uppbox: AutoTest git-svn-id: svn://ultimatepp.org/upp/trunk@7114 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppbox/AutoTest/AutoTest.cpp | 153 +++++++++++++++++++++++++++++++++++ uppbox/AutoTest/AutoTest.upp | 11 +++ uppbox/AutoTest/init | 6 ++ 3 files changed, 170 insertions(+) create mode 100644 uppbox/AutoTest/AutoTest.cpp create mode 100644 uppbox/AutoTest/AutoTest.upp create mode 100644 uppbox/AutoTest/init diff --git a/uppbox/AutoTest/AutoTest.cpp b/uppbox/AutoTest/AutoTest.cpp new file mode 100644 index 000000000..33d129166 --- /dev/null +++ b/uppbox/AutoTest/AutoTest.cpp @@ -0,0 +1,153 @@ +#include + +using namespace Upp; + +String infolog; +String errors; + +String input; + +Vector exclude; + +void Do(const char *nest, const char *bm, bool release, bool test) +{ + String flags = release ? "r" : "b"; + String mn = release ? "R" : "D"; + String n = String().Cat() << nest << '-' << bm << '-' << mn; + Cout() << n << '\n'; + infolog << "========== " << nest << " " << bm << (release ? "-R" : "") << " =============\n"; + FindFile ff(AppendFileName(AppendFileName(input, nest), "*.*")); + bool first = true; + while(ff) { + String name = ff.GetName(); + String upp = AppendFileName(ff.GetPath(), name + ".upp"); + String h = String(nest) + "/" + name; + if(ff.IsFolder() && !ff.IsHidden() && FindIndex(exclude, h) < 0) { + String txt; + txt << bm; + if(release) + txt << "-R "; + txt << ' ' << h << ' '; + String c; + c << "umk " << nest << ' ' << name << ' ' << bm << " -" << flags; + if(first) + c << 'a'; + #ifdef PLATFORM_POSIX + c << 's'; + #endif + String exe = GetHomeDirFile("autotest.tst"); + c << ' ' << exe; + Cout() << c << '\n'; + infolog << txt; + String out; + if(Sys(c, out)) { + Cout() << " *** FAILED TO COMPILE\n"; + infolog << ": FAILED TO COMPILE\n"; + errors << txt << ": FAILED TO COMPILE\n"; + } + else { + infolog << ": BUILD OK"; + if(test) { + LocalProcess p; + if(!p.Start(exe)) { + Cout() << "FAILED TO RUN\n"; + infolog << ", FAILED TO RUN"; + errors << txt << ": FAILED TO RUN\n"; + } + else { + Cout() << "RUN\n"; + #ifdef _DEBUG + int timeout = 10000; + #else + int timeout = 60000; + #endif + String h = LoadFile(upp); + int q = h.Find("#WAIT:"); + if(q >= 0) { + timeout = max(60 * 1000 * atoi(~h + q + strlen("#WAIT:")), timeout); + } + int msecs0 = msecs(); + for(;;) { + if(p.IsRunning()) { + if(msecs(msecs0) > timeout) { + infolog << ", TIMEOUT"; + errors << txt << ": TIMEOUT\n"; + Cout() << "*** TIMEOUT\n"; + break; + } + } + else { + if(p.GetExitCode()) { + infolog << ", FAILED"; + errors << txt << ": FAILED\n"; + Cout() << "*** FAILED\n"; + } + else + infolog << ", OK"; + Cout() << "OK\n"; + break; + } + Sleep(10); + } + } + } + infolog << "\n"; + } + first = false; + DeleteFile(exe); + } + ff.Next(); + } +} + +CONSOLE_APP_MAIN +{ + Value ini = ParseJSON(LoadFile(GetHomeDirFile("autotest.ini"))); + + input = ini["upp_sources"]; + Vector test = Split((String)ini["auto_test"], ';'); + Vector build = Split((String)ini["build_test"], ';'); + Vector bm = Split((String)ini["build_method"], ';'); + exclude = Split((String)ini["exclude"], ';'); + + infolog << "Started " << GetSysTime() << "\n"; + + bm.Add("GCC"); + bm.Add("GCC11"); + + for(int i = 0; i < bm.GetCount(); i++) { + for(int j = 0; j < test.GetCount(); j++) { + Do(test[j], bm[i], false, true); + Do(test[j], bm[i], true, false); + } + for(int j = 0; j < build.GetCount(); j++) { + Do(build[j], bm[i], false, false); + Do(build[j], bm[i], true, false); + } + } + + + infolog << "Finished " << GetSysTime() << "\n"; + + String body; + if(errors.GetCount()) { + body << "FAILED TESTS:\n" << errors << "\n---------------------------\n\n"; + SetExitCode(1); + } + body << "TEST LOG:\n" << infolog; + + Smtp smtp; + smtp.Trace(); + smtp.Host(ini["smtp_server"]) + .Port(Nvl((int)ini["smtp_port"], 465)) + .SSL() + .Auth(ini["smtp_user"], ini["smtp_password"]) + .Subject(String().Cat() << "U++ autotest: " << (errors.GetCount() ? "** FAILED **" : "OK")) + .Body(body) + ; + + Vector s = Split((String)ini["emails"], ';'); + for(int i = 0; i < s.GetCount(); i++) + smtp.To(s[i]); + smtp.Send(); +} diff --git a/uppbox/AutoTest/AutoTest.upp b/uppbox/AutoTest/AutoTest.upp new file mode 100644 index 000000000..e3c73816f --- /dev/null +++ b/uppbox/AutoTest/AutoTest.upp @@ -0,0 +1,11 @@ +uses + Core, + Core/SMTP, + Core/SSL; + +file + AutoTest.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/uppbox/AutoTest/init b/uppbox/AutoTest/init new file mode 100644 index 000000000..bb1814807 --- /dev/null +++ b/uppbox/AutoTest/init @@ -0,0 +1,6 @@ +#ifndef _AutoTest_icpp_init_stub +#define _AutoTest_icpp_init_stub +#include "Core/init" +#include "Core/SMTP/init" +#include "Core/SSL/init" +#endif