1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.mj.impl.rt.test; |
|
19 |
|
20 import com.nokia.mj.impl.installer.utils.InstallerMain; |
|
21 import com.nokia.mj.impl.rt.support.JvmInternal; |
|
22 import com.nokia.mj.impl.rt.support.ThreadEventListener; |
|
23 import com.nokia.mj.impl.utils.Logger; |
|
24 import com.nokia.mj.impl.utils.Tokenizer; |
|
25 |
|
26 |
|
27 public class UnitTestRunner |
|
28 { |
|
29 /** |
|
30 * UnitTestRunner main program. |
|
31 * |
|
32 * @param args command line arguments |
|
33 */ |
|
34 public static void main(String[] args) |
|
35 { |
|
36 int exitCode = 0; |
|
37 |
|
38 System.out.println("java.version: " + |
|
39 System.getProperty("java.version")); |
|
40 System.out.println("java.fullversion: " + |
|
41 System.getProperty("java.fullversion")); |
|
42 |
|
43 if (args.length == 0) |
|
44 { |
|
45 Logger.ELOG(Logger.EJavaRuntime, "No args provided."); |
|
46 exitCode = -2; |
|
47 } |
|
48 try |
|
49 { |
|
50 JvmInternal.setThreadEventListener(new ThreadEventListener() |
|
51 { |
|
52 public void threadStarting(Thread newThread, Thread parentThread) {} |
|
53 public void threadDied(Thread thread) {} |
|
54 public void uncaughtException(Thread thread, Throwable throwable) |
|
55 { |
|
56 String threadName = null; |
|
57 if (thread != null) |
|
58 { |
|
59 threadName = thread.getName(); |
|
60 } |
|
61 Logger.ELOG(Logger.EJavaRuntime, "Unhandled exception in " + |
|
62 threadName, throwable); |
|
63 System.exit(-1); |
|
64 } |
|
65 }); |
|
66 test(args); |
|
67 } |
|
68 catch (Throwable t) |
|
69 { |
|
70 Logger.ELOG(Logger.EJavaRuntime, "Unhandled exception in main", t); |
|
71 exitCode = -1; |
|
72 } |
|
73 System.exit(exitCode); |
|
74 } |
|
75 |
|
76 /** |
|
77 * Main program for executing tests. |
|
78 */ |
|
79 private static void test(String[] args) |
|
80 { |
|
81 String mainClass = getMainClass(args[0]); |
|
82 if (mainClass == null) |
|
83 { |
|
84 Logger.ELOG(Logger.EJavaRuntime, "Mainclass must be specified."); |
|
85 return; |
|
86 } |
|
87 |
|
88 try |
|
89 { |
|
90 // Instantiate mainclass and call its main() method. |
|
91 Class clazz = Class.forName(mainClass); |
|
92 InstallerMain instMain = (InstallerMain)clazz.newInstance(); |
|
93 instMain.installerMain(args); |
|
94 } |
|
95 catch (Exception ex) |
|
96 { |
|
97 Logger.ELOG(Logger.EJavaRuntime, "Running mainclass failed", ex); |
|
98 } |
|
99 } |
|
100 |
|
101 /** |
|
102 * Main program for executing tests. |
|
103 */ |
|
104 private static String getMainClass(String arg) |
|
105 { |
|
106 String[] mainClassArg = Tokenizer.split(arg, "="); |
|
107 if (mainClassArg.length != 2) |
|
108 { |
|
109 return null; |
|
110 } |
|
111 if (!mainClassArg[0].equals("-mainclass")) |
|
112 { |
|
113 return null; |
|
114 } |
|
115 return mainClassArg[1]; |
|
116 |
|
117 } |
|
118 |
|
119 /** |
|
120 * Logs arguments given to TCK Runner |
|
121 */ |
|
122 private static void logArgs(String[] args) |
|
123 { |
|
124 StringBuffer buf = new StringBuffer("UnitTestRunner args:"); |
|
125 for (int i = 0; i < args.length; i++) |
|
126 { |
|
127 buf.append(" "); |
|
128 buf.append(args[i]); |
|
129 } |
|
130 Logger.ILOG(Logger.EJavaRuntime, buf.toString()); |
|
131 } |
|
132 |
|
133 } |
|