From c38dad733a81178c2f49210a339f9c21f99e0343 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Fri, 2 Jun 2017 07:49:26 +0000
Subject: [PATCH] Task #9893: Fixed tests after merge: use LOFARROOT in
 t_gpu_utils to place ad-hoc GPU kernels in the right build dir

---
 .gitattributes                          |  1 +
 RTCP/Cobalt/GPUProc/test/t_gpu_utils.cc | 13 ++++++++-----
 RTCP/Cobalt/GPUProc/test/t_gpu_utils.sh |  3 +++
 3 files changed, 12 insertions(+), 5 deletions(-)
 create mode 100755 RTCP/Cobalt/GPUProc/test/t_gpu_utils.sh

diff --git a/.gitattributes b/.gitattributes
index 298a39e151c..ea111ad3cfd 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -4403,6 +4403,7 @@ RTCP/Cobalt/GPUProc/test/tMPIReceive.sh eol=lf
 RTCP/Cobalt/GPUProc/test/t_cpu_utils.in_parset -text
 RTCP/Cobalt/GPUProc/test/t_generate_globalfs_locations.in_parset -text
 RTCP/Cobalt/GPUProc/test/t_generate_globalfs_locations.sh eol=lf
+RTCP/Cobalt/GPUProc/test/t_gpu_utils.sh eol=lf
 RTCP/Cobalt/InputProc/doc/Cobalt-New-InputSection.jpg -text svneol=unset#image/jpeg
 RTCP/Cobalt/InputProc/src/Delays/printDelays.log_prop -text
 RTCP/Cobalt/InputProc/src/ping_intl.sh -text
diff --git a/RTCP/Cobalt/GPUProc/test/t_gpu_utils.cc b/RTCP/Cobalt/GPUProc/test/t_gpu_utils.cc
index 163156176a8..420b54dc463 100644
--- a/RTCP/Cobalt/GPUProc/test/t_gpu_utils.cc
+++ b/RTCP/Cobalt/GPUProc/test/t_gpu_utils.cc
@@ -24,7 +24,8 @@
 #ifdef USE_CUDA
 
 #include <cstdio>    // for remove()
-#include <cstdlib>   // for unsetenv()
+#include <cstdlib>   // for getenv()
+#include <cassert>
 #include <vector>
 #include <fstream>
 #include <stdexcept>
@@ -47,8 +48,12 @@ const char* srcFile("t_gpu_utils.cl");
 struct CreateFixture
 {
   CreateFixture() {
-    ofstream ofs(srcFile);
-    if (!ofs) throw runtime_error("Failed to create file: " + string(srcFile));
+    assert(getenv("LOFARROOT"));
+
+    string lofarroot = getenv("LOFARROOT");
+    string fullFilename = lofarroot + "/share/gpu/kernels/" + srcFile;
+    ofstream ofs(fullFilename.c_str());
+    if (!ofs) throw runtime_error("Failed to create file: " + string(fullFilename));
     ofs << "#if defined FOO && FOO != 42\n"
         << "#error FOO != 42\n"
         << "#endif\n"
@@ -163,8 +168,6 @@ int main()
 {
   INIT_LOGGER("t_gpu_utils");
 
-  unsetenv("LOFARROOT");
-
   try {
     gpu::Platform pf;
     return UnitTest::RunAllTests() > 0;
diff --git a/RTCP/Cobalt/GPUProc/test/t_gpu_utils.sh b/RTCP/Cobalt/GPUProc/test/t_gpu_utils.sh
new file mode 100755
index 00000000000..b66a1953356
--- /dev/null
+++ b/RTCP/Cobalt/GPUProc/test/t_gpu_utils.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+./runctest.sh t_gpu_utils
-- 
GitLab