|
21 | 21 | package org.apache.sysds.test.component.misc;
|
22 | 22 |
|
23 | 23 |
|
| 24 | +import org.apache.commons.cli.ParseException; |
24 | 25 | import org.apache.log4j.Level;
|
25 | 26 | import org.apache.log4j.Logger;
|
26 | 27 | import org.apache.log4j.spi.LoggingEvent;
|
27 | 28 | import org.apache.sysds.api.DMLScript;
|
| 29 | +import org.apache.sysds.api.ScriptExecutorUtils; |
| 30 | +import org.apache.sysds.conf.ConfigurationManager; |
28 | 31 | import org.apache.sysds.parser.LanguageException;
|
| 32 | +import org.apache.sysds.runtime.controlprogram.context.ExecutionContext; |
| 33 | +import org.apache.sysds.runtime.controlprogram.context.ExecutionContextFactory; |
29 | 34 | import org.apache.sysds.test.LoggingUtils;
|
30 | 35 | import org.junit.Assert;
|
31 | 36 | import org.junit.Test;
|
32 | 37 |
|
33 | 38 | import java.io.ByteArrayOutputStream;
|
34 | 39 | import java.io.IOException;
|
35 | 40 | import java.io.PrintStream;
|
| 41 | +import java.util.Arrays; |
36 | 42 | import java.util.List;
|
37 | 43 | import java.util.concurrent.ExecutorService;
|
38 | 44 | import java.util.concurrent.Executors;
|
@@ -359,5 +365,44 @@ public void executeDMLWithScriptAndDebugTest() throws IOException {
|
359 | 365 | public void createDMLScriptInstance(){
|
360 | 366 | DMLScript script = new DMLScript();
|
361 | 367 | Assert.assertTrue(script != null);
|
| 368 | + |
| 369 | + } |
| 370 | + |
| 371 | + @Test |
| 372 | + public void testLineageScriptExecutorUtilTestTest() throws IOException { |
| 373 | + // just for code coverage |
| 374 | + new ScriptExecutorUtils(); |
| 375 | + |
| 376 | + String cl = "systemds -lineage estimate -s \"print('hello')\""; |
| 377 | + String[] args = cl.split(" "); |
| 378 | + final PrintStream originalOut = System.out; |
| 379 | + try { |
| 380 | + final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); |
| 381 | + System.setOut(new PrintStream(outputStreamCaptor)); |
| 382 | + executeScript(args); |
| 383 | + System.setOut(originalOut); |
| 384 | + String[] lines = outputStreamCaptor.toString().split(System.lineSeparator()); |
| 385 | + Assert.assertTrue(lines[0].startsWith("hello")); |
| 386 | + Assert.assertTrue(Arrays.stream(lines).anyMatch(s -> s.startsWith("Compute Time (Elapsed/Saved):"))); |
| 387 | + Assert.assertTrue(Arrays.stream(lines).anyMatch(s -> s.startsWith("Space Used (C/R/L):"))); |
| 388 | + Assert.assertTrue(Arrays.stream(lines).anyMatch(s -> s.startsWith("Cache Full Timestamp:"))); |
| 389 | + } finally { |
| 390 | + System.setOut(originalOut); |
| 391 | + } |
| 392 | + } |
| 393 | + |
| 394 | + @Test |
| 395 | + public void testScriptExecutorUtilTestTest() throws IOException, ParseException { |
| 396 | + boolean old = DMLScript.USE_ACCELERATOR; |
| 397 | + DMLScript.USE_ACCELERATOR = true; |
| 398 | + try { |
| 399 | + ExecutionContext ec = ExecutionContextFactory.createContext(); |
| 400 | + ScriptExecutorUtils.executeRuntimeProgram(null, ec, ConfigurationManager.getDMLConfig(), 0, null); |
| 401 | + } catch (Error e){ |
| 402 | + Assert.assertTrue("Expecting Message starting with \"Error while loading native library. Instead got:" |
| 403 | + + e.getMessage(), e.getMessage().startsWith("Error while loading native library")); |
| 404 | + } finally { |
| 405 | + DMLScript.USE_ACCELERATOR = old; |
| 406 | + } |
362 | 407 | }
|
363 | 408 | }
|
0 commit comments