Update kunit.sh to handle upstream KUnit .kunitconfig

When KUnit was upstreamed we moved kunitconfig to .kunitconfig, so
handle that so we can support both upstream KUnit as well as
kunit/alpha/master.

Change-Id: Ic758b17ba609331897a2e88baaa262bb9d9bda17
diff --git a/kunit.sh b/kunit.sh
index 14d0319..7dcb702 100755
--- a/kunit.sh
+++ b/kunit.sh
@@ -18,15 +18,28 @@
 # Prow may not create artifacts folder in advance.
 mkdir -p "$ARTIFACTS"
 
-# Include kunitconfig manually until we can pull it from prowjob TODO(avikr)
-cp /kunitconfig ./kunitconfig
+# KUnit repos based on upstream have a default kunitconfig; we can check for
+# that to see if we are running a repo based on upstream or not.
+#
+# TODO(brendanhiggins): handle the case where .kunitconfig is stored in .kunit/
+# when that happens.
+if [[ -f ./arch/um/configs/kunit_defconfig ]]; then
+  if [[ ! -f .kunitconfig ]]; then
+    cp ./arch/um/configs/kunit_defconfig .kunitconfig
+  fi
+  cp .kunitconfig .config
+else
+  if [[ ! -f ./kunitconfig ]]; then
+    cp /kunitconfig ./kunitconfig
+  fi
+  cp kunitconfig .config
+fi
 
 # Add correct configs to .config to make GCOV flags work
-cp kunitconfig .config
 echo -e "CONFIG_DEBUG_KERNEL=y\nCONFIG_DEBUG_INFO=y\nCONFIG_GCOV=y" >> .config
 
 # Run the KUnit tool unit tests
-if [[ -f ./tools/testing/kunit/kunit_test.py ]]
+if [[ -f ./tools/testing/kunit/kunit_test.py ]]; then
   python3 ./tools/testing/kunit/kunit_test.py > "$ARTIFACTS/kunit_test.log" 2>&1
 else # for upstream version
   python3 ./tools/testing/kunit/kunit_tool_test.py > "$ARTIFACTS/kunit_test.log" 2>&1