• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package vogar.android;
18 
19 import java.io.IOException;
20 import java.util.Arrays;
21 import java.util.List;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.runners.MockitoJUnitRunner;
25 import vogar.LocalTarget;
26 import vogar.Mode;
27 import vogar.ModeId;
28 import vogar.Target;
29 import vogar.Variant;
30 import vogar.commands.Command;
31 import vogar.commands.VmCommandBuilder;
32 
33 import static org.junit.Assert.assertEquals;
34 
35 /**
36  * Test the behaviour of the {@link HostRuntime} class when run with {@link LocalTarget}.
37  */
38 @RunWith(MockitoJUnitRunner.class)
39 public class HostRuntimeLocalTargetTest extends AbstractModeTest {
40 
41     @Override
createTarget()42     protected Target createTarget() {
43         return new LocalTarget(console, mkdir, rm);
44     }
45 
46     @Test
47     @VogarArgs({"action"})
testLocalTarget()48     public void testLocalTarget()
49             throws IOException {
50 
51         Mode hostRuntime = new HostRuntime(run, ModeId.HOST, Variant.X32);
52 
53         VmCommandBuilder builder = newVmCommandBuilder(hostRuntime)
54                 .classpath(classpath)
55                 .mainClass("mainclass")
56                 .args("-x", "a b");
57         Command command = builder.build(run.target);
58         List<String> args = command.getArgs();
59         assertEquals(Arrays.asList(
60                 "sh", "-c", ""
61                         + "ANDROID_PRINTF_LOG=tag"
62                         + " ANDROID_LOG_TAGS=*:i"
63                         + " ANDROID_DATA=" + run.localFile("android-data")
64                         + " ANDROID_ROOT=out/host/linux-x86"
65                         + " LD_LIBRARY_PATH=out/host/linux-x86/lib"
66                         + " DYLD_LIBRARY_PATH=out/host/linux-x86/lib"
67                         + " LD_USE_LOAD_BIAS=1"
68                         + " out/host/linux-x86/bin/dalvikvm32"
69                         + " -classpath classes"
70                         + " -Xbootclasspath"
71                         + ":out/host/linux-x86/framework/core-libart-hostdex.jar"
72                         + ":out/host/linux-x86/framework/conscrypt-hostdex.jar"
73                         + ":out/host/linux-x86/framework/okhttp-hostdex.jar"
74                         + ":out/host/linux-x86/framework/bouncycastle-hostdex.jar"
75                         + " -Duser.language=en"
76                         + " -Duser.region=US"
77                         + " -Xcheck:jni"
78                         + " -Xjnigreflimit:2000"
79                         + " mainclass"
80                         + " -x a\\ b"), args);
81     }
82 
83     @Test
84     @VogarArgs({"--benchmark", "action"})
testLocalTarget_Benchmark()85     public void testLocalTarget_Benchmark()
86             throws IOException {
87 
88         Mode hostRuntime = new HostRuntime(run, ModeId.HOST, Variant.X32);
89 
90         VmCommandBuilder builder = newVmCommandBuilder(hostRuntime)
91                 .classpath(classpath)
92                 .mainClass("mainclass")
93                 .args("-x", "a b");
94         Command command = builder.build(run.target);
95         List<String> args = command.getArgs();
96         assertEquals(Arrays.asList(
97                 "sh", "-c", ""
98                         + "ANDROID_PRINTF_LOG=tag"
99                         + " ANDROID_LOG_TAGS=*:i"
100                         + " ANDROID_DATA=" + run.localFile("android-data")
101                         + " ANDROID_ROOT=out/host/linux-x86"
102                         + " LD_LIBRARY_PATH=out/host/linux-x86/lib"
103                         + " DYLD_LIBRARY_PATH=out/host/linux-x86/lib"
104                         + " LD_USE_LOAD_BIAS=1"
105                         + " out/host/linux-x86/bin/dalvikvm32"
106                         + " -classpath classes"
107                         + " -Xbootclasspath"
108                         + ":out/host/linux-x86/framework/core-libart-hostdex.jar"
109                         + ":out/host/linux-x86/framework/conscrypt-hostdex.jar"
110                         + ":out/host/linux-x86/framework/okhttp-hostdex.jar"
111                         + ":out/host/linux-x86/framework/bouncycastle-hostdex.jar"
112                         + " -Duser.language=en"
113                         + " -Duser.region=US"
114                         + " -Xjnigreflimit:2000"
115                         + " mainclass"
116                         + " -x a\\ b"), args);
117     }
118 }
119