This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
CommandConfigurationTest.java
124 lines (101 loc) · 3.93 KB
/
CommandConfigurationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*******************************************************************************
* Copyright (c) 2019- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings, Joe Osborn
*******************************************************************************/
package org.eclipse.ice.tests.commands;
import java.util.ArrayList;
import org.eclipse.ice.commands.CommandConfiguration;
import org.junit.Test;
/**
* This class tests {@link org.eclipse.ice.commands.CommandConfiguration}.
*
* @author Joe Osborn
*
*/
public class CommandConfigurationTest {
// Create a default instance to test
CommandConfiguration config = new CommandConfiguration();
/**
* Test method for
* {@link org.eclipse.ice.commands.CommandConfiguration#CommandConfiguration()}.
* Check some of the getters and setters
*/
@Test
public void testCommandConfiguration() {
// Set some things
config.setCommandId(3);
config.setExecutable("./some_executable.sh");
config.setErrFileName("errorFile.txt");
config.setOutFileName("outFile.txt");
// Assert whether or not things are/aren't set
assert (config.getOutFileName() != null);
assert (config.getOS() != null);
// Didn't set working directory
assert (config.getWorkingDirectory() == null);
// Assert that the default local OS is set
assert (config.getOS().equals(System.getProperty("os.name")));
config.setOS("JoeOsbornOS");
assert (config.getOS().equals("JoeOsbornOS"));
}
/**
* Test method for
* {@link org.eclipse.ice.commands.CommandConfiguration#getExecutableName()}
*/
@Test
public void testGetExecutableName() {
// Test that if one wants to append inputfile, it is appended
config.setCommandId(1);
config.setExecutable("./test_code_execution.sh");
config.setInputFile("someInputFile.txt");
config.setNumProcs("1");
config.setAppendInput(true);
config.setOS("osx");
String executable = config.getExecutableName();
assert (executable.equals("./test_code_execution.sh someInputFile.txt"));
// Test that if num processes is more than 1, mpi options are added
config.setNumProcs("4"); // arbitrary number
// We can test append input as well when it is false
config.setAppendInput(false);
executable = config.getExecutableName();
assert (executable.equals("mpirun -np 4 ./test_code_execution.sh"));
}
/**
* Test method for
* {@link org.eclipse.ice.commands.CommandConfiguration#getExecutableName()} and
* for testing the split command functionality
*/
@Test
public void testGetExecutableNameSplitCommand() {
CommandConfiguration splitConfig = new CommandConfiguration();
splitConfig.setCommandId(2);
splitConfig
.setExecutable("./dummy.sh ${inputFile}; ./next_file.sh ${inputFile}; ./other_file.sh ${installDir}");
// Test if the user falsifies append input whether or not the environment
// variable is replaced
splitConfig.setAppendInput(false);
splitConfig.setNumProcs("1");
splitConfig.setInputFile("inputfile.txt");
splitConfig.setInstallDirectory("~/install_dir");
splitConfig.setOS("osx");
String executable = splitConfig.getExecutableName();
assert (executable
.equals("./dummy.sh inputfile.txt; ./next_file.sh inputfile.txt; ./other_file.sh ~/install_dir/"));
ArrayList<String> split = new ArrayList<String>();
split = splitConfig.getSplitCommand();
// Create an array list to check the split command against
ArrayList<String> checkSplit = new ArrayList<String>();
checkSplit.add("./dummy.sh inputfile.txt");
checkSplit.add("./next_file.sh inputfile.txt");
checkSplit.add("./other_file.sh ~/install_dir/");
for (int i = 0; i < split.size(); i++) {
assert (split.get(i).equals(checkSplit.get(i)));
}
}
}