This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompilertest.cc
183 lines (145 loc) · 6.16 KB
/
compilertest.cc
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Copyright 2017 Battelle Energy Alliance, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Description
-----------
subclass of base class SrcTest.
Part of HPC Software Test Suite.
Date Created: Wed Nov 11 13:31:39 MST 2015
Author: Cormac Garvey
*/
#include "compilertest.h"
#include <iostream> // for debugging only
#include <cstdlib> // for exit()
namespace hpcswtest {
const std::vector<std::string> CompilerTest::c_srcs_ = {
R"(
#include <stdio.h>
#include <math.h>
int main(){
double d, r;
d = 0.0;
r = cos(d);
printf("cos(%4.2f)=%4.2f\n",d,r);
printf("C code is working\n");
}
)"
}; // vector c_srcs_
const std::vector<std::string> CompilerTest::cpp_srcs_ = {
R"(
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
double d, r;
d = 0.0;
r=cos(d);
cout << setprecision(2) << "cos(" << d << ")=" << setw(2) << r << endl;
cout << "C code is working\n";
}
)"
}; // vector cpp_srcs_
const std::vector<std::string> CompilerTest::f_srcs_ = {
R"(
program fff
double precision d,r
d = 0.0
r = cos(d)
write(6,10)d,r
10 format(1x,'cos(',F6.2,')=',F6.2)
write(6,*)'F90 code is working'
end
)"
}; // vector f_srcs_
CompilerTest::CompilerTest(const jobscript::JOBSCRIPT &p_s, const std::string &c_n, const std::string &cpp_n, const std::string &f_n, const std::string &c_f, const std::string &cpp_f, const std::string &f_f, const std::string &c_l_l, const std::string &cpp_l_l, const std::string &f_l_l): SrcTest("compiler", p_s, c_n, cpp_n, f_n, c_srcs_.size(), cpp_srcs_.size(), f_srcs_.size(), c_f, cpp_f, f_f, c_l_l, cpp_l_l, f_l_l),
log_file_name_(getHostName() + "_" + getTestName() + "_test.log"),
result_file_name_(getHostName() + "_" + getTestName() + "_results.out"),
flog_(log_file_name_,std::ios_base::app),
fresult_(result_file_name_,std::ios_base::app) {}
void CompilerTest::runTest(void) {
std::string cmd_result;
std::string script_cmd_result;
std::time_t date_result = std::time(NULL);
// std::cout << "Execute runTest member function from CompilerTest object " << __FILE__ << "\t" <<__LINE__ << std::endl;
if (!flog_.is_open()) {
std::cerr << "Error: (" << __FILE__ << "," << __LINE__ << ") Opening file " << log_file_name_ << std::endl;
exit(EXIT_FAILURE);
}
if (!fresult_.is_open()) {
std::cerr << "Error: (" << __FILE__ << "," << __LINE__ << ") Opening file " << result_file_name_ << std::endl;
exit(EXIT_FAILURE);
}
int c_i = 0;
if (getCName() != "none") {
for (auto c_src: c_srcs_) {
cmd_result = compileTest(flog_, getCJobScripts()[c_i], getCSrc(c_i), getCName(), getCFlags(), getCSrcName(c_i), getCExeName(c_i), getCLinkLibs());
checkCompileResult(cmd_result, getCName(), findPrimaryModule(getCJobScripts()[c_i].getModules()).first, findPrimaryModule(getCJobScripts()[c_i].getModules()).second, getCJobScripts()[c_i].getJobName(), flog_, fresult_);
script_cmd_result = srcExeTest(flog_, getCJobScripts()[c_i]);
checkSubmitResult(script_cmd_result, flog_, fresult_);
++c_i;
}
}
c_i = 0;
if (getCppName() != "none") {
for (auto cpp_src: cpp_srcs_) {
cmd_result = compileTest(flog_, getCppJobScripts()[c_i], getCppSrc(c_i), getCppName(), getCppFlags(), getCppSrcName(c_i), getCppExeName(c_i), getCppLinkLibs());
checkCompileResult(cmd_result, getCppName(), findPrimaryModule(getCppJobScripts()[c_i].getModules()).first, findPrimaryModule(getCppJobScripts()[c_i].getModules()).second, getCppJobScripts()[c_i].getJobName(), flog_, fresult_);
script_cmd_result = srcExeTest(flog_, getCppJobScripts()[c_i]);
checkSubmitResult(script_cmd_result, flog_, fresult_);
++c_i;
}
}
c_i = 0;
if (getFName() != "none") {
for (auto f_src: f_srcs_) {
cmd_result = compileTest(flog_, getFJobScripts()[c_i], getFSrc(c_i), getFName(), getFFlags(), getFSrcName(c_i), getFExeName(c_i), getFLinkLibs());
checkCompileResult(cmd_result, getFName(), findPrimaryModule(getFJobScripts()[c_i].getModules()).first, findPrimaryModule(getFJobScripts()[c_i].getModules()).second, getFJobScripts()[c_i].getJobName(), flog_, fresult_);
script_cmd_result = srcExeTest(flog_, getFJobScripts()[c_i]);
checkSubmitResult(script_cmd_result, flog_, fresult_);
++c_i;
}
}
}
int CompilerTest::NumCSrc(void) const {
return c_srcs_.size();
}
std::string CompilerTest::getCSrc(int i) const {
if (i >= 0 and i <= NumCSrc()) {
return c_srcs_[i];
} else {
std::cerr << "Error: Illegal index(" << i << ") in CompilerTest member function getCSrc\n" << std::endl;
exit(EXIT_FAILURE);
}
}
int CompilerTest::NumCppSrc(void) const {
return cpp_srcs_.size();
}
std::string CompilerTest::getCppSrc(int i) const {
if (i >= 0 and i <= NumCppSrc()) {
return cpp_srcs_[i];
} else {
std::cerr << "Error: Illegal index(" << i << ") in CompilerTest member function getCppSrc\n" << std::endl;
exit(EXIT_FAILURE);
}
}
int CompilerTest::NumFSrc(void) const {
return f_srcs_.size();
}
std::string CompilerTest::getFSrc(int i) const {
if (i >= 0 and i <= NumFSrc()) {
return f_srcs_[i];
} else {
std::cerr << "Error: Illegal index(" << i << ") in CompilerTest member function getFSrc\n" << std::endl;
exit(EXIT_FAILURE);
}
}
} // namespace hpcswtest