You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/08/15 08:19:11 UTC

[GitHub] [tvm] gigiblender opened a new pull request, #12436: [CI] Assert some unittests are not skipped

gigiblender opened a new pull request, #12436:
URL: https://github.com/apache/tvm/pull/12436

   This PR adds a script that does a diff of skipped tests between the latest successful build on the main and the current branch. Then, it posts a comment with the report on the open PR. 
   
   @driazati @areusch


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] gigiblender commented on a diff in pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
gigiblender commented on code in PR #12436:
URL: https://github.com/apache/tvm/pull/12436#discussion_r952893155


##########
tests/scripts/github_skipped_tests_comment.py:
##########
@@ -0,0 +1,206 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+import os
+import logging
+import argparse
+import subprocess
+import sys
+from urllib import error
+from xml.etree import ElementTree
+
+import requests
+
+from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import init_log
+
+SKIPPED_TESTS_COMMENT_MARKER = "<!---skipped-tests-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
+PR_TEST_REPORT_DIR = "pr-reports"
+MAIN_TEST_REPORT_DIR = "main-reports"
+
+
+def retrieve_test_report(s3_url, target_dir):
+    command = f"aws s3 cp {s3_url} {target_dir} --recursive"
+    logging.info(f"Running command {command}")
+    proc = subprocess.run(command, shell=True, stdout=subprocess.PIPE, encoding="utf-8")
+    if proc.returncode != 0:
+        raise RuntimeError(f"Command failed {command}:\nstdout:\n{proc.stdout}")
+
+
+def retrieve_test_reports(pr_number, build_number, s3_prefix, jenkins_prefix):
+    cur_build_s3_link = (
+        f"s3://{s3_prefix}/tvm/PR-{str(pr_number)}/{str(build_number)}/pytest-results"
+    )
+    retrieve_test_report(cur_build_s3_link, PR_TEST_REPORT_DIR)
+
+    latest_main_build = requests.get(
+        f"https://{jenkins_prefix}/job/tvm/job/main/lastSuccessfulBuild/buildNumber"

Review Comment:
   Thanks! That should be implemented now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] github-actions[bot] commented on pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #12436:
URL: https://github.com/apache/tvm/pull/12436#issuecomment-1214876424

   <!---docs-bot-comment-->
   
   Built docs for commit 183f5135c9f90321c64b083760ea2847178025cb can be found [here](https://pr-docs.tlcpack.ai/PR-12436/1/docs/index.html).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] gigiblender commented on a diff in pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
gigiblender commented on code in PR #12436:
URL: https://github.com/apache/tvm/pull/12436#discussion_r951636137


##########
tests/scripts/github_skipped_tests_comment.py:
##########
@@ -0,0 +1,206 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+import os
+import logging
+import argparse
+import subprocess
+import sys
+from urllib import error
+from xml.etree import ElementTree
+
+import requests
+
+from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import init_log
+
+SKIPPED_TESTS_COMMENT_MARKER = "<!---skipped-tests-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
+PR_TEST_REPORT_DIR = "pr-reports"
+MAIN_TEST_REPORT_DIR = "main-reports"
+
+
+def retrieve_test_report(s3_url, target_dir):
+    command = f"aws s3 cp {s3_url} {target_dir} --recursive"
+    logging.info(f"Running command {command}")
+    proc = subprocess.run(command, shell=True, stdout=subprocess.PIPE, encoding="utf-8")
+    if proc.returncode != 0:
+        raise RuntimeError(f"Command failed {command}:\nstdout:\n{proc.stdout}")
+
+
+def retrieve_test_reports(pr_number, build_number, s3_prefix, jenkins_prefix):
+    cur_build_s3_link = (
+        f"s3://{s3_prefix}/tvm/PR-{str(pr_number)}/{str(build_number)}/pytest-results"
+    )
+    retrieve_test_report(cur_build_s3_link, PR_TEST_REPORT_DIR)
+
+    latest_main_build = requests.get(
+        f"https://{jenkins_prefix}/job/tvm/job/main/lastSuccessfulBuild/buildNumber"

Review Comment:
   > Looks pretty great! This is a nice way to fix this without putting too much burden on developers. It’d be nice to see a end to end test in your tvm fork too
   
   Coming back to this. I applied some end-to-end testing in [my fork. ](https://github.com/gigiblender/tvm/pull/2). [Here is a version](https://github.com/gigiblender/tvm/actions/runs/2905368093) that does a diff with an [older build](https://ci.tlcpack.ai/job/tvm/job/PR-12436/1/). Then [this is a](https://github.com/gigiblender/tvm/runs/7956165144?check_suite_focus=true) version that performs the diff with an up-to-date build. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] driazati commented on a diff in pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
driazati commented on code in PR #12436:
URL: https://github.com/apache/tvm/pull/12436#discussion_r954601652


##########
tests/python/ci/test_ci.py:
##########
@@ -33,6 +34,168 @@ def parameterize_named(*values):
     return pytest.mark.parametrize(",".join(keys), [tuple(d.values()) for d in values])
 
 
+@tvm.testing.skip_if_wheel_test
+@pytest.mark.parametrize(
+    # pylint: disable=line-too-long
+    "main_xml_file,main_xml_content,pr_xml_file,pr_xml_content,target_url,s3_prefix,"

Review Comment:
   also the test names here that pytest autogenerates and shows in test reports are crazy long since they include the whole junit string, could you also pass through `ids=[...]` with a short name for each case? i.e. something similar to https://github.com/apache/tvm/blob/main/tests/python/ci/test_tvmbot.py#L141-L145



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] driazati commented on a diff in pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
driazati commented on code in PR #12436:
URL: https://github.com/apache/tvm/pull/12436#discussion_r951790460


##########
tests/scripts/github_skipped_tests_comment.py:
##########
@@ -0,0 +1,206 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+import os
+import logging
+import argparse
+import subprocess
+import sys
+from urllib import error
+from xml.etree import ElementTree
+
+import requests
+
+from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import init_log
+
+SKIPPED_TESTS_COMMENT_MARKER = "<!---skipped-tests-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
+PR_TEST_REPORT_DIR = "pr-reports"
+MAIN_TEST_REPORT_DIR = "main-reports"
+
+
+def retrieve_test_report(s3_url, target_dir):
+    command = f"aws s3 cp {s3_url} {target_dir} --recursive"
+    logging.info(f"Running command {command}")
+    proc = subprocess.run(command, shell=True, stdout=subprocess.PIPE, encoding="utf-8")
+    if proc.returncode != 0:
+        raise RuntimeError(f"Command failed {command}:\nstdout:\n{proc.stdout}")
+
+
+def retrieve_test_reports(pr_number, build_number, s3_prefix, jenkins_prefix):
+    cur_build_s3_link = (
+        f"s3://{s3_prefix}/tvm/PR-{str(pr_number)}/{str(build_number)}/pytest-results"
+    )
+    retrieve_test_report(cur_build_s3_link, PR_TEST_REPORT_DIR)
+
+    latest_main_build = requests.get(
+        f"https://{jenkins_prefix}/job/tvm/job/main/lastSuccessfulBuild/buildNumber"

Review Comment:
   `git merge-base origin/main HEAD` should find the commit to check (though I'm not 100% sure if that works after we do a `git merge` so we might have to do it beforehand. Then we can use the [GitHub Status API](https://docs.github.com/en/rest/commits/statuses#about-the-commit-statuses-api) to find the Jenkins link



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] driazati commented on a diff in pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
driazati commented on code in PR #12436:
URL: https://github.com/apache/tvm/pull/12436#discussion_r948295471


##########
tests/scripts/github_skipped_tests_comment.py:
##########
@@ -0,0 +1,206 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+import os
+import logging
+import argparse
+import subprocess
+import sys
+from urllib import error
+from xml.etree import ElementTree
+
+import requests
+
+from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import init_log
+
+SKIPPED_TESTS_COMMENT_MARKER = "<!---skipped-tests-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
+PR_TEST_REPORT_DIR = "pr-reports"
+MAIN_TEST_REPORT_DIR = "main-reports"
+
+
+def retrieve_test_report(s3_url, target_dir):
+    command = f"aws s3 cp {s3_url} {target_dir} --recursive"
+    logging.info(f"Running command {command}")
+    proc = subprocess.run(command, shell=True, stdout=subprocess.PIPE, encoding="utf-8")
+    if proc.returncode != 0:
+        raise RuntimeError(f"Command failed {command}:\nstdout:\n{proc.stdout}")
+
+
+def retrieve_test_reports(pr_number, build_number, s3_prefix, jenkins_prefix):
+    cur_build_s3_link = (
+        f"s3://{s3_prefix}/tvm/PR-{str(pr_number)}/{str(build_number)}/pytest-results"
+    )
+    retrieve_test_report(cur_build_s3_link, PR_TEST_REPORT_DIR)
+
+    latest_main_build = requests.get(
+        f"https://{jenkins_prefix}/job/tvm/job/main/lastSuccessfulBuild/buildNumber"

Review Comment:
   Would this be confusing in the case of a PR running on an older base branch? Tests that have been merged to main in the meantime would show up as missing on the PR. It seems like this would need to find the build for the base `main` commit of the PR and then locate that build



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] driazati merged pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
driazati merged PR #12436:
URL: https://github.com/apache/tvm/pull/12436


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] driazati commented on a diff in pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
driazati commented on code in PR #12436:
URL: https://github.com/apache/tvm/pull/12436#discussion_r953102085


##########
tests/python/ci/test_ci.py:
##########
@@ -33,6 +35,168 @@ def parameterize_named(*values):
     return pytest.mark.parametrize(",".join(keys), [tuple(d.values()) for d in values])
 
 
+@tvm.testing.skip_if_wheel_test
+@pytest.mark.parametrize(
+    # pylint: disable=line-too-long
+    "main_xml_file,main_xml_content,pr_xml_file,pr_xml_content,target_url,s3_prefix,"
+    "jenkins_prefix,common_main_build,commit_sha,expected_url,expected_body",
+    [
+        (
+            "unittest/file1.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                <testsuites>
+                    <testsuite errors="0" failures="0" hostname="13e7c5f749d8" name="python-unittest-gpu-0-shard-1-ctypes" skipped="102"
+                               tests="165" time="79.312" timestamp="2022-08-10T22:39:36.673781">
+                        <testcase classname="ctypes.tests.python.unittest.test_auto_scheduler_search_policy"
+                                  name="test_sketch_search_policy_cuda_rpc_runner" time="9.679">
+                        </testcase>
+                    </testsuite>
+                </testsuites>
+                """,
+            "unittest/file2.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                <testsuites>
+                    <testsuite errors="0" failures="0" hostname="13e7c5f749d8" name="python-unittest-gpu-0-shard-1-ctypes" skipped="102"
+                               tests="165" time="79.312" timestamp="2022-08-10T22:39:36.673781">
+                        <testcase classname="ctypes.tests.python.unittest.test_auto_scheduler_search_policy"
+                                  name="test_sketch_search_policy_cuda_rpc_runner" time="9.679">
+                            <skipped message="This test is skipped" type="pytest.skip">
+                                Skipped
+                            </skipped>
+                        </testcase>
+                        <testcase classname="ctypes.tests.python.unittest.test_roofline"
+                                  name="test_estimate_peak_bandwidth[cuda]" time="4.679">
+                            <skipped message="This is another skippe test" type="pytest.skip">
+                                Skipped
+                            </skipped>
+                        </testcase>
+                    </testsuite>
+                </testsuites>
+                """,
+            "https://ci.tlcpack.ai/job/tvm/job/PR-11594/3/display/redirect",
+            "tvm-jenkins-artifacts-prod",
+            "ci.tlcpack.ai",
+            """{"build_number": "4115", "state": "success"}""",
+            "SHA",
+            "issues/11594/comments",
+            """<!---skipped-tests-comment-->\n\nThe list below shows some tests that ran in main SHA but were skipped in the CI build of SHA:\n```\nunittest -> ctypes.tests.python.unittest.test_auto_scheduler_search_policy#test_sketch_search_policy_cuda_rpc_runner\nunittest -> ctypes.tests.python.unittest.test_roofline#test_estimate_peak_bandwidth[cuda]\n```\nA detailed report of ran tests is [here](https://ci.tlcpack.ai/job/tvm/job/PR-11594/3/testReport/).""",
+        ),
+        (
+            "unittest/file1.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                <testsuites>
+                    <testsuite errors="0" failures="0" hostname="13e7c5f749d8" name="python-unittest-gpu-0-shard-1-ctypes" skipped="102"
+                               tests="165" time="79.312" timestamp="2022-08-10T22:39:36.673781">
+                        <testcase classname="ctypes.tests.python.unittest.test_auto_scheduler_search_policy"
+                                  name="test_sketch_search_policy_cuda_rpc_runner" time="9.679">
+                            <skipped message="This test is skipped" type="pytest.skip">
+                                Skipped
+                            </skipped>
+                        </testcase>
+                    </testsuite>
+                </testsuites>
+                """,
+            "unittest/file2.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                <testsuites>
+                    <testsuite errors="0" failures="0" hostname="13e7c5f749d8" name="python-unittest-gpu-0-shard-1-ctypes" skipped="102"
+                               tests="165" time="79.312" timestamp="2022-08-10T22:39:36.673781">
+                        <testcase classname="ctypes.tests.python.unittest.test_auto_scheduler_search_policy"
+                                  name="test_sketch_search_policy_cuda_rpc_runner" time="9.679">
+                            <skipped message="This test is skipped" type="pytest.skip">
+                                Skipped
+                            </skipped>
+                        </testcase>
+                    </testsuite>
+                </testsuites>
+                """,
+            "https://ci.tlcpack.ai/job/tvm/job/PR-11594/3/display/redirect",
+            "tvm-jenkins-artifacts-prod",
+            "ci.tlcpack.ai",
+            """{"build_number": "4115", "state": "success"}""",
+            "SHA",
+            "issues/11594/comments",
+            """<!---skipped-tests-comment-->\n\nNo additional skipped tests found in this branch for commit SHA.""",
+        ),
+        (
+            "unittest/file1.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                    <testsuites>
+                    </testsuites>
+                    """,
+            "unittest/file2.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                    <testsuites>
+                    </testsuites>
+                    """,
+            "https://ci.tlcpack.ai/job/tvm/job/PR-11594/3/display/redirect",
+            "tvm-jenkins-artifacts-prod",
+            "ci.tlcpack.ai",
+            """{"build_number": "4115", "state": "failed"}""",
+            "SHA",
+            "issues/11594/comments",
+            """<!---skipped-tests-comment-->\n\nUnable to run tests bot because main failed to pass CI at SHA.""",
+        ),
+    ],
+)
+# pylint: enable=line-too-long
+def test_skipped_tests_comment(
+    tmpdir_factory,
+    main_xml_file,
+    main_xml_content,
+    pr_xml_file,
+    pr_xml_content,
+    target_url,
+    s3_prefix,
+    jenkins_prefix,
+    common_main_build,
+    commit_sha,
+    expected_url,
+    expected_body,
+):
+    """
+    Test that a comment with a link to the docs is successfully left on PRs
+    """
+    skipped_tests_script = REPO_ROOT / "tests" / "scripts" / "github_skipped_tests_comment.py"
+
+    def write_xml_file(root_dir, xml_file, xml_content):
+        shutil.rmtree(root_dir, ignore_errors=True)
+        file = f"""{root_dir}/{xml_file}"""
+        os.makedirs(os.path.dirname(file))
+        with open(file, "w") as f:
+            f.write(textwrap.dedent(xml_content))
+
+    git = TempGit(tmpdir_factory.mktemp("tmp_git_dir"))
+    git.run("init")
+    git.run("checkout", "-b", "main")
+    git.run("remote", "add", "origin", "https://github.com/apache/tvm.git")
+
+    pr_test_report_dir = git.cwd + "/pr-reports"

Review Comment:
   nit: use `pathlib.Path` here and elsewhere in this test so these tests are cross-platform
   
   ```suggestion
       pr_test_report_dir = Path(git.cwd) / "pr-reports"
   ```



##########
tests/scripts/github_skipped_tests_comment.py:
##########
@@ -0,0 +1,255 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+import json
+import os
+import logging
+import argparse
+import subprocess
+import sys
+from urllib import error
+from xml.etree import ElementTree
+
+import requests
+
+from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import init_log
+
+SKIPPED_TESTS_COMMENT_MARKER = "<!---skipped-tests-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
+PR_TEST_REPORT_DIR = "pr-reports"
+MAIN_TEST_REPORT_DIR = "main-reports"
+
+
+def run_subprocess(command):
+    logging.info(f"Running command {command}")
+    proc = subprocess.run(command, shell=True, stdout=subprocess.PIPE, encoding="utf-8")
+    if proc.returncode != 0:
+        raise RuntimeError(f"Command failed {command}:\nstdout:\n{proc.stdout}")
+    return proc
+
+
+def retrieve_test_report(s3_url, target_dir):
+    command = f"aws s3 cp {s3_url} {target_dir} --recursive"
+    run_subprocess(command)
+
+
+def get_common_commit_sha():
+    command = "git merge-base origin/main HEAD"
+    proc = run_subprocess(command)
+    return proc.stdout.strip()
+
+
+def get_main_jenkins_build_number(common_commit):
+    json = requests.get(
+        f"https://api.github.com/repos/apache/tvm/commits/{common_commit}/status"
+    ).json()

Review Comment:
   afaik we don't install `requests` in CI (though maybe we should...) either way you should be able to use `git_utils.GitHubRepo.get` to get this info (and pass along the github actions `GITHUB_TOKEN` so this doesn't hit API limits)



##########
tests/scripts/github_skipped_tests_comment.py:
##########
@@ -0,0 +1,255 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+import json
+import os
+import logging
+import argparse
+import subprocess
+import sys
+from urllib import error
+from xml.etree import ElementTree
+
+import requests
+
+from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import init_log
+
+SKIPPED_TESTS_COMMENT_MARKER = "<!---skipped-tests-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
+PR_TEST_REPORT_DIR = "pr-reports"
+MAIN_TEST_REPORT_DIR = "main-reports"
+
+
+def run_subprocess(command):
+    logging.info(f"Running command {command}")
+    proc = subprocess.run(command, shell=True, stdout=subprocess.PIPE, encoding="utf-8")
+    if proc.returncode != 0:
+        raise RuntimeError(f"Command failed {command}:\nstdout:\n{proc.stdout}")
+    return proc
+
+
+def retrieve_test_report(s3_url, target_dir):
+    command = f"aws s3 cp {s3_url} {target_dir} --recursive"
+    run_subprocess(command)
+
+
+def get_common_commit_sha():
+    command = "git merge-base origin/main HEAD"
+    proc = run_subprocess(command)
+    return proc.stdout.strip()
+
+
+def get_main_jenkins_build_number(common_commit):
+    json = requests.get(
+        f"https://api.github.com/repos/apache/tvm/commits/{common_commit}/status"
+    ).json()
+    statuses_len = len(json["statuses"])
+    last_status = json["statuses"][statuses_len - 1]
+    assert last_status["context"] == "tvm-ci/branch"

Review Comment:
   can you do a search over all the `statuses` instead? it's possible to attach others to commits so there could be both a `tvm-ci/branch` and `tvm-ci/pr-head`



##########
tests/python/ci/test_ci.py:
##########
@@ -33,6 +35,168 @@ def parameterize_named(*values):
     return pytest.mark.parametrize(",".join(keys), [tuple(d.values()) for d in values])
 
 
+@tvm.testing.skip_if_wheel_test
+@pytest.mark.parametrize(
+    # pylint: disable=line-too-long
+    "main_xml_file,main_xml_content,pr_xml_file,pr_xml_content,target_url,s3_prefix,"
+    "jenkins_prefix,common_main_build,commit_sha,expected_url,expected_body",
+    [
+        (
+            "unittest/file1.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                <testsuites>
+                    <testsuite errors="0" failures="0" hostname="13e7c5f749d8" name="python-unittest-gpu-0-shard-1-ctypes" skipped="102"
+                               tests="165" time="79.312" timestamp="2022-08-10T22:39:36.673781">
+                        <testcase classname="ctypes.tests.python.unittest.test_auto_scheduler_search_policy"
+                                  name="test_sketch_search_policy_cuda_rpc_runner" time="9.679">
+                        </testcase>
+                    </testsuite>
+                </testsuites>
+                """,
+            "unittest/file2.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                <testsuites>
+                    <testsuite errors="0" failures="0" hostname="13e7c5f749d8" name="python-unittest-gpu-0-shard-1-ctypes" skipped="102"
+                               tests="165" time="79.312" timestamp="2022-08-10T22:39:36.673781">
+                        <testcase classname="ctypes.tests.python.unittest.test_auto_scheduler_search_policy"
+                                  name="test_sketch_search_policy_cuda_rpc_runner" time="9.679">
+                            <skipped message="This test is skipped" type="pytest.skip">
+                                Skipped
+                            </skipped>
+                        </testcase>
+                        <testcase classname="ctypes.tests.python.unittest.test_roofline"
+                                  name="test_estimate_peak_bandwidth[cuda]" time="4.679">
+                            <skipped message="This is another skippe test" type="pytest.skip">
+                                Skipped
+                            </skipped>
+                        </testcase>
+                    </testsuite>
+                </testsuites>
+                """,
+            "https://ci.tlcpack.ai/job/tvm/job/PR-11594/3/display/redirect",
+            "tvm-jenkins-artifacts-prod",
+            "ci.tlcpack.ai",
+            """{"build_number": "4115", "state": "success"}""",
+            "SHA",
+            "issues/11594/comments",
+            """<!---skipped-tests-comment-->\n\nThe list below shows some tests that ran in main SHA but were skipped in the CI build of SHA:\n```\nunittest -> ctypes.tests.python.unittest.test_auto_scheduler_search_policy#test_sketch_search_policy_cuda_rpc_runner\nunittest -> ctypes.tests.python.unittest.test_roofline#test_estimate_peak_bandwidth[cuda]\n```\nA detailed report of ran tests is [here](https://ci.tlcpack.ai/job/tvm/job/PR-11594/3/testReport/).""",
+        ),
+        (
+            "unittest/file1.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                <testsuites>
+                    <testsuite errors="0" failures="0" hostname="13e7c5f749d8" name="python-unittest-gpu-0-shard-1-ctypes" skipped="102"
+                               tests="165" time="79.312" timestamp="2022-08-10T22:39:36.673781">
+                        <testcase classname="ctypes.tests.python.unittest.test_auto_scheduler_search_policy"
+                                  name="test_sketch_search_policy_cuda_rpc_runner" time="9.679">
+                            <skipped message="This test is skipped" type="pytest.skip">
+                                Skipped
+                            </skipped>
+                        </testcase>
+                    </testsuite>
+                </testsuites>
+                """,
+            "unittest/file2.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                <testsuites>
+                    <testsuite errors="0" failures="0" hostname="13e7c5f749d8" name="python-unittest-gpu-0-shard-1-ctypes" skipped="102"
+                               tests="165" time="79.312" timestamp="2022-08-10T22:39:36.673781">
+                        <testcase classname="ctypes.tests.python.unittest.test_auto_scheduler_search_policy"
+                                  name="test_sketch_search_policy_cuda_rpc_runner" time="9.679">
+                            <skipped message="This test is skipped" type="pytest.skip">
+                                Skipped
+                            </skipped>
+                        </testcase>
+                    </testsuite>
+                </testsuites>
+                """,
+            "https://ci.tlcpack.ai/job/tvm/job/PR-11594/3/display/redirect",
+            "tvm-jenkins-artifacts-prod",
+            "ci.tlcpack.ai",
+            """{"build_number": "4115", "state": "success"}""",
+            "SHA",
+            "issues/11594/comments",
+            """<!---skipped-tests-comment-->\n\nNo additional skipped tests found in this branch for commit SHA.""",
+        ),
+        (
+            "unittest/file1.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                    <testsuites>
+                    </testsuites>
+                    """,
+            "unittest/file2.xml",
+            """<?xml version="1.0" encoding="utf-8"?>
+                    <testsuites>
+                    </testsuites>
+                    """,
+            "https://ci.tlcpack.ai/job/tvm/job/PR-11594/3/display/redirect",
+            "tvm-jenkins-artifacts-prod",
+            "ci.tlcpack.ai",
+            """{"build_number": "4115", "state": "failed"}""",
+            "SHA",
+            "issues/11594/comments",
+            """<!---skipped-tests-comment-->\n\nUnable to run tests bot because main failed to pass CI at SHA.""",
+        ),
+    ],
+)
+# pylint: enable=line-too-long
+def test_skipped_tests_comment(
+    tmpdir_factory,
+    main_xml_file,
+    main_xml_content,
+    pr_xml_file,
+    pr_xml_content,
+    target_url,
+    s3_prefix,
+    jenkins_prefix,
+    common_main_build,
+    commit_sha,
+    expected_url,
+    expected_body,
+):
+    """
+    Test that a comment with a link to the docs is successfully left on PRs
+    """
+    skipped_tests_script = REPO_ROOT / "tests" / "scripts" / "github_skipped_tests_comment.py"
+
+    def write_xml_file(root_dir, xml_file, xml_content):
+        shutil.rmtree(root_dir, ignore_errors=True)
+        file = f"""{root_dir}/{xml_file}"""
+        os.makedirs(os.path.dirname(file))

Review Comment:
   nit: same pathlib deal here
   ```suggestion
           file = root_dir / xml_file
           file.parent.mkdir(parents=True)
   ```



##########
tests/scripts/github_skipped_tests_comment.py:
##########
@@ -0,0 +1,255 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+import json
+import os
+import logging
+import argparse
+import subprocess
+import sys
+from urllib import error
+from xml.etree import ElementTree
+
+import requests
+
+from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import init_log
+
+SKIPPED_TESTS_COMMENT_MARKER = "<!---skipped-tests-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
+PR_TEST_REPORT_DIR = "pr-reports"
+MAIN_TEST_REPORT_DIR = "main-reports"
+
+
+def run_subprocess(command):
+    logging.info(f"Running command {command}")
+    proc = subprocess.run(command, shell=True, stdout=subprocess.PIPE, encoding="utf-8")
+    if proc.returncode != 0:
+        raise RuntimeError(f"Command failed {command}:\nstdout:\n{proc.stdout}")
+    return proc
+
+
+def retrieve_test_report(s3_url, target_dir):
+    command = f"aws s3 cp {s3_url} {target_dir} --recursive"
+    run_subprocess(command)
+
+
+def get_common_commit_sha():
+    command = "git merge-base origin/main HEAD"
+    proc = run_subprocess(command)
+    return proc.stdout.strip()
+
+
+def get_main_jenkins_build_number(common_commit):
+    json = requests.get(
+        f"https://api.github.com/repos/apache/tvm/commits/{common_commit}/status"
+    ).json()
+    statuses_len = len(json["statuses"])
+    last_status = json["statuses"][statuses_len - 1]
+    assert last_status["context"] == "tvm-ci/branch"
+    state = last_status["state"]
+    target_url = str(last_status["target_url"])
+    build_number = (
+        target_url[target_url.find("job/main") : len(target_url)]
+        .strip("job/main/")
+        .strip("/display/redirect")
+    )
+    assert build_number.isdigit()
+    return {"build_number": build_number, "state": state}
+
+
+def retrieve_test_reports(common_main_build, pr_number, build_number, s3_prefix):
+    cur_build_s3_link = (
+        f"s3://{s3_prefix}/tvm/PR-{str(pr_number)}/{str(build_number)}/pytest-results"
+    )
+    retrieve_test_report(cur_build_s3_link, PR_TEST_REPORT_DIR)
+
+    common_build_s3_link = f"s3://{s3_prefix}/tvm/main/{common_main_build}/pytest-results"
+    retrieve_test_report(common_build_s3_link, MAIN_TEST_REPORT_DIR)
+
+
+def get_pr_and_build_numbers(target_url):
+    target_url = target_url[target_url.find("PR-") : len(target_url)]
+    split = target_url.split("/")
+    pr_number = split[0].strip("PR-")
+    build_number = split[1]
+    return {"pr_number": pr_number, "build_number": build_number}
+
+
+def build_test_set(directory):
+    subdir_to_skipped = {}
+    subdirs = [
+        item for item in os.listdir(directory) if os.path.isdir(os.path.join(directory, item))
+    ]
+    for subdir in subdirs:
+        subdir_to_skipped[subdir] = set()
+        for root, _, files in os.walk(directory + "/" + subdir):
+            for file in files:
+                test_report = ElementTree.parse(root + "/" + file)
+                for testcase in test_report.iter("testcase"):
+                    skipped = testcase.find("skipped")
+                    if skipped is not None:
+                        key = testcase.attrib["classname"] + "#" + testcase.attrib["name"]
+                        subdir_to_skipped[subdir].add(key)
+    return subdir_to_skipped
+
+
+def to_node_name(dir_name: str):
+    return dir_name.replace("_", ": ", 1)
+
+
+def build_comment(
+    common_commit_sha,
+    common_main_build,
+    skipped_list,
+    pr_number,
+    build_number,
+    commit_sha,
+    jenkins_prefix,
+):
+    if common_main_build["state"] != "success":
+        return f"{SKIPPED_TESTS_COMMENT_MARKER}Unable to run tests bot because main failed to pass CI at {common_commit_sha}."
+
+    if len(skipped_list) == 0:
+        return f"{SKIPPED_TESTS_COMMENT_MARKER}No additional skipped tests found in this branch for commit {commit_sha}."
+
+    text = (
+        f"{SKIPPED_TESTS_COMMENT_MARKER}The list below shows some tests that ran in main {common_commit_sha} but were "
+        f"skipped in the CI build of {commit_sha}:\n"
+        f"```\n"
+    )
+    for skip in skipped_list:
+        text += skip + "\n"
+    text += (
+        f"```\nA detailed report of ran tests is [here](https://{jenkins_prefix}/job/tvm/job/PR-{str(pr_number)}"
+        f"/{str(build_number)}/testReport/)."
+    )
+    return text
+
+
+def get_pr_comments(github, url):
+    try:
+        return github.get(url)
+    except error.HTTPError as e:
+        logging.exception(f"Failed to retrieve PR comments: {url}: {e}")
+        return []
+
+
+def search_for_docs_comment(comments):
+    for comment in comments:
+        if (
+            comment["user"]["login"] == GITHUB_ACTIONS_BOT_LOGIN
+            and SKIPPED_TESTS_COMMENT_MARKER in comment["body"]
+        ):
+            return comment
+    return None
+
+
+if __name__ == "__main__":
+    help = (
+        "Compares the skipped tests of this PR against the last successful build on main. Also comments on the PR "
+        "issue when tests are skipped in this PR and not on main."
+    )
+    parser = argparse.ArgumentParser(description=help)
+    parser.add_argument("--remote", default="origin", help="ssh remote to parse")
+    parser.add_argument("--s3-prefix", default="tvm-jenkins-artifacts-prod")
+    parser.add_argument("--jenkins-prefix", default="ci.tlcpack.ai")
+    parser.add_argument("--common-main-build")
+    parser.add_argument(
+        "--dry-run",
+        action="store_true",
+        default=False,
+        help="run but don't send any request to GitHub",
+    )
+    args = parser.parse_args()
+    init_log()
+
+    remote = git(["config", "--get", f"remote.{args.remote}.url"])
+    user, repo = parse_remote(remote)
+
+    target_url = os.environ["TARGET_URL"]
+    pr_and_build = get_pr_and_build_numbers(target_url)
+
+    commit_sha = os.environ["COMMIT_SHA"]
+
+    if not args.dry_run:
+        common_commit_sha = get_common_commit_sha()
+        common_main_build = get_main_jenkins_build_number(common_commit_sha)
+        retrieve_test_reports(
+            common_main_build=common_main_build["build_number"],
+            pr_number=pr_and_build["pr_number"],
+            build_number=pr_and_build["build_number"],
+            s3_prefix=args.s3_prefix,
+        )
+    else:
+        assert args.common_main_build is not None
+        common_main_build = json.loads(args.common_main_build)
+        common_commit_sha = os.environ["COMMIT_SHA"]
+
+    main_tests = build_test_set(MAIN_TEST_REPORT_DIR)
+    build_tests = build_test_set(PR_TEST_REPORT_DIR)
+
+    skipped_list = []
+    for subdir, skipped_set in build_tests.items():
+        skipped_main = main_tests[subdir]
+        if skipped_main is None:
+            logging.warning(f"Could not find directory {subdir} in main.")
+            continue
+
+        diff_set = skipped_set - skipped_main
+        if len(diff_set) != 0:
+            for test in diff_set:
+                skipped_list.append(f"{to_node_name(subdir)} -> {test}")
+
+    if len(skipped_list) == 0:
+        logging.info("No skipped tests found.")
+
+    body = build_comment(
+        common_commit_sha,
+        common_main_build,
+        skipped_list,
+        pr_and_build["pr_number"],
+        pr_and_build["build_number"],
+        commit_sha,
+        args.jenkins_prefix,
+    )
+    url = f'issues/{pr_and_build["pr_number"]}/comments'
+    if not args.dry_run:
+        github = GitHubRepo(token=os.environ["GITHUB_TOKEN"], user=user, repo=repo)
+
+        # For now, only comment for PRs open by driazati, gigiblender and areusch.
+        get_pr_url = f'pulls/{pr_and_build["pr_number"]}'
+        pull_request_body = github.get(get_pr_url)
+        author = pull_request_body["user"]["login"]
+        if author not in ["driazati", "gigiblender", "areusch"]:

Review Comment:
   🚀 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] gigiblender commented on a diff in pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
gigiblender commented on code in PR #12436:
URL: https://github.com/apache/tvm/pull/12436#discussion_r951639870


##########
tests/scripts/github_skipped_tests_comment.py:
##########
@@ -0,0 +1,206 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+import os
+import logging
+import argparse
+import subprocess
+import sys
+from urllib import error
+from xml.etree import ElementTree
+
+import requests
+
+from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import init_log
+
+SKIPPED_TESTS_COMMENT_MARKER = "<!---skipped-tests-comment-->\n\n"
+GITHUB_ACTIONS_BOT_LOGIN = "github-actions[bot]"
+
+PR_TEST_REPORT_DIR = "pr-reports"
+MAIN_TEST_REPORT_DIR = "main-reports"
+
+
+def retrieve_test_report(s3_url, target_dir):
+    command = f"aws s3 cp {s3_url} {target_dir} --recursive"
+    logging.info(f"Running command {command}")
+    proc = subprocess.run(command, shell=True, stdout=subprocess.PIPE, encoding="utf-8")
+    if proc.returncode != 0:
+        raise RuntimeError(f"Command failed {command}:\nstdout:\n{proc.stdout}")
+
+
+def retrieve_test_reports(pr_number, build_number, s3_prefix, jenkins_prefix):
+    cur_build_s3_link = (
+        f"s3://{s3_prefix}/tvm/PR-{str(pr_number)}/{str(build_number)}/pytest-results"
+    )
+    retrieve_test_report(cur_build_s3_link, PR_TEST_REPORT_DIR)
+
+    latest_main_build = requests.get(
+        f"https://{jenkins_prefix}/job/tvm/job/main/lastSuccessfulBuild/buildNumber"

Review Comment:
   Also, I am not sure how to find the Jenkins build number for the base `main` commit that is part of the current PR (in case the PR branch i not up to date with `main`). Do you have any suggestions on how I could do that?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] gigiblender commented on a diff in pull request #12436: [CI] Assert some unittests are not skipped in CI

Posted by GitBox <gi...@apache.org>.
gigiblender commented on code in PR #12436:
URL: https://github.com/apache/tvm/pull/12436#discussion_r954768873


##########
tests/python/ci/test_ci.py:
##########
@@ -33,6 +34,168 @@ def parameterize_named(*values):
     return pytest.mark.parametrize(",".join(keys), [tuple(d.values()) for d in values])
 
 
+@tvm.testing.skip_if_wheel_test
+@pytest.mark.parametrize(
+    # pylint: disable=line-too-long
+    "main_xml_file,main_xml_content,pr_xml_file,pr_xml_content,target_url,s3_prefix,"

Review Comment:
   Thanks! Seems like a test was also flaky due to different order of reported skipped tests. That should be sorted now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org