[WIP] Add codecov support
diff --git a/.circleci/config.yml b/.circleci/config.yml
index c2c7e53..f8df0e6 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -2,6 +2,7 @@
 
 orbs:
   win: circleci/windows@1.0.0
+  codecov: codecov/codecov@3
 
 executors:
   linux-node:
@@ -237,6 +238,24 @@
           command: |
             ./test/runner << parameters.test_targets >>
             $EMSDK_PYTHON ./test/check_clean.py
+  run-tests-coverage:
+    description: "Runs emscripten tests (with coverage)"
+    parameters:
+      test_targets:
+        description: "Test suites to run"
+        type: string
+      title:
+        description: "Name of given test suite"
+        type: string
+        default: ""
+    steps:
+      - run:
+          name: run tests (<< parameters.title >>)
+          command: |
+            ./tools/emcoverage.py ./test/runner.py << parameters.test_targets >>
+            $EMSDK_PYTHON ./test/check_clean.py
+      - run: tools/emcoverage.py xml
+      - codecov/upload
   freeze-cache:
     description: "Freeze emscripten cache"
     steps:
@@ -498,7 +517,7 @@
             lsan.test_dlfcn_basic
             lsan.test_pthread_create"
       - freeze-cache
-      - run-tests:
+      - run-tests-coverage:
           # also run a single test of EMTEST_BROWSER=node.
           # also run a corez test of dynamic linking + forced syslibs.
           title: "core2+extras"
diff --git a/tools/emcoverage.py b/tools/emcoverage.py
index d7d906d..1fd7219 100755
--- a/tools/emcoverage.py
+++ b/tools/emcoverage.py
@@ -72,7 +72,12 @@
   if not os.path.exists(sys.argv[1]):
     # If argv[1] is not a file path, instead try to interpret it as an emscripten command.
     # This allows `emcoverage.py emcc` or `emcoverage.py embuilder` to work.
-    sys.argv[1] = os.path.join(os.path.dirname(sys.executable), '..', sys.argv[1] + '.py')
+    pyfile = os.path.join(os.path.dirname(sys.executable), '..', sys.argv[1] + '.py')
+    if os.path.exists(pyfile):
+      sys.argv[1] = pyfile
+
+  if sys.argv[1] == '-E':
+    del sys.argv[1]
 
   try:
     os.mkdir(store)