//function to send test logs to repository public static void SendTestLogsToRepo(CommMessage rcvMsg) { Console.Write("\n\n===================================================================================\n\n"); Console.Write("Sending test logs from {0}", System.IO.Path.GetFullPath(ClientEnvironment.fileStorage)); Console.Write("\n\n===================================================================================\n\n"); LogFileName = rcvMsg.arguments[0]; Console.Write("\n\n===================================================================================\n\n"); Console.Write("Log file Name is {0}", "TestLogs_" + LogFileName); Console.Write("\n\n===================================================================================\n\n"); Console.Write("Sending file {0}", "TestLogs_" + LogFileName); Console.Write("\n\n===================================================================================\n\n"); sndr.postFile("TestLogs_" + LogFileName + ".txt", 0, LogFileName); Thread.Sleep(3000); CommMessage sndMsg = new CommMessage(CommMessage.MessageType.request); sndMsg.command = "TestLogsSent"; sndMsg.author = "Akash Bhosale"; string toAddress = baseAddress + ":" + "8078" + "/IpluggableComm"; string fromAddress = baseAddress + ":" + "8077" + "/IpluggableComm"; sndMsg.to = toAddress; sndMsg.from = fromAddress; sndr.postMessage(sndMsg); DllLoaderExec.CleanPath(); }
//----< load assemblies from testersLocation and run their tests >----- public string loadAndExerciseTesters(string finalLocation, string dll_name) { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromComponentLibFolder); string txt_name = "../../../TestHarness/TestHarnessStorage/" + dll_name + "_" + DateTime.Now.ToString("HHmmssfff") + ".txt"; try { DllLoaderExec loader = new DllLoaderExec(); string[] files = Directory.GetFiles(finalLocation, dll_name); foreach (string file in files) { Assembly asm = Assembly.LoadFile(file); string fileName = Path.GetFileName(file); Console.Write("\n loaded {0}", fileName); // exercise each tester found in assembly Type[] types = asm.GetTypes(); using (System.IO.StreamWriter log = File.AppendText(txt_name)) { log.WriteLine("Test Harness Log :\n Filename {0} \n ", fileName); foreach (Type t in types) { // if type supports ITest interface then run test if (t.GetInterface("DllLoaderDemo.ITest", true) != null) { if (!loader.runSimulatedTest(t, asm)) { Console.Write("\n test {0} failed to run", t.ToString()); log.WriteLine(DateTime.Now.ToString() + ": \n test {0} failed to run", t.ToString(), true); } else { log.WriteLine(DateTime.Now.ToString() + ": \n test {0} succeeded to run", t.ToString(), true); } } } } } } catch (Exception ex) { return(ex.Message); } Console.WriteLine("Simulated Testing completed"); return(txt_name); }
//function to perform operations after receiving builds public static void AcceptBuild() { var directories = System.IO.Directory.GetDirectories(ServiceEnvironment.fileStorage); foreach (string dir in directories) { var subdirectories = System.IO.Directory.GetDirectories(dir); foreach (string subdirectory in subdirectories) { string[] buildFiles = System.IO.Directory.GetFiles(subdirectory); foreach (string file in buildFiles) { if (System.IO.File.Exists(System.IO.Path.Combine(buildPath, System.IO.Path.GetFileName(file)))) { try { System.IO.File.Delete(System.IO.Path.Combine(buildPath, System.IO.Path.GetFileName(file))); } catch (Exception ex) { ex.ToString(); } } try { System.IO.File.Move(file, System.IO.Path.Combine(buildPath, System.IO.Path.GetFileName(file))); } catch (Exception ex) { ex.ToString(); } string[] buildFiles1 = System.IO.Directory.GetFiles(subdirectory); if (buildFiles1.Length == 0) { System.IO.Directory.Delete(subdirectory); } var subdirectories1 = System.IO.Directory.GetDirectories(dir); if (subdirectories1.Length == 0) { System.IO.Directory.Delete(dir); } LogFileName = System.IO.Path.GetFileNameWithoutExtension(file); DllLoaderExec.UpdateDllLoader(buildPath, System.IO.Path.GetFileNameWithoutExtension(file)); DllLoaderExec.InitiateTest(); SendMsgtoRepo(LogFileName); } } } }
public static void load(string j) { Thread.Sleep(2000); string testpath = "../../../ThFileStore" + "/" + j + "TR.xml"; Console.WriteLine(testpath); try { parse("lib", testpath); } catch { Console.WriteLine("invalid test request or no lib"); } string fileStorage = "../../../ThFileStore"; DllLoaderExec.UpdateDllLoader(fileStorage, j, values.ToArray()); DllLoaderExec.InitiateTest(); sendtestlogs_conn(j); }
/*------------------Calling the .dll execute function and transferring the test logs to repository------------------------------*/ public void parseXmlForDll(CommMessage rcv) { List <string> parsed_files = new List <string>(); loadXml(testpath + rcv.arguments.ElementAt(1)); parsed_files.AddRange(parseList("testDriver")); DllLoaderExec dllexe = new DllLoaderExec(); List <string> txt_files = new List <string>(); foreach (string s in parsed_files) { Console.WriteLine("parsed file in parseXMl for dll function=" + s); testpath = Path.GetFullPath(testpath); Console.WriteLine("\n Meeting requirement 9 of project 4 where the test harness attempts to load each test library it receives" + "and executes it. \n"); txt_files.Add(Path.GetFileName(dllexe.loadAndExerciseTesters(testpath, s))); } Thread.Sleep(500); Console.WriteLine("\n Meeting requirement 9 of project 4 where results of testing are submitted to the repository \n"); ClientEnvironment.fileStorage = testpath; CommMessage comm = new CommMessage(CommMessage.MessageType.request); comm.to = "http://localhost:8079/IPluggableComm"; comm.from = "TestHarness"; comm.command = "Sending_Test_Logs"; comm.arguments.AddRange(txt_files); send_to_repo.postMessage(comm); Thread.Sleep(500); foreach (string file in comm.arguments) { { TestUtilities.putLine(string.Format("transferring file \"{0}\"", file)); bool transferSuccess = send_to_repo.postFile(file, repo_path); TestUtilities.checkResult(transferSuccess, "transfer"); } } }