Skip to content

[lldb][test] Set target OS for API tests in case of remote testing #96654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

dzhidzhoev
Copy link
Member

Makefile.rules uses HOST_OS and OS variables for determining host and target OSes for API tests compilation.

When lldb's target is set to remote-linux, Makefile.rules script should be executed with the target OS variable set to Linux.

This is useful for the case of Windows-to-Linux cross-testing.

@llvmbot
Copy link
Member

llvmbot commented Jun 25, 2024

@llvm/pr-subscribers-lldb

Author: Vladislav Dzhidzhoev (dzhidzhoev)

Changes

Makefile.rules uses HOST_OS and OS variables for determining host and target OSes for API tests compilation.

When lldb's target is set to remote-linux, Makefile.rules script should be executed with the target OS variable set to Linux.

This is useful for the case of Windows-to-Linux cross-testing.


Full diff: https://github.com/llvm/llvm-project/pull/96654.diff

1 Files Affected:

  • (modified) lldb/packages/Python/lldbsuite/test/lldbplatformutil.py (+7)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 21f2095db90f8..c39d297a78f8f 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -56,6 +56,10 @@ def target_is_android():
     return configuration.lldb_platform_name == "remote-android"
 
 
+def target_is_remote_linux():
+    return configuration.lldb_platform_name == "remote-linux"
+
+
 def android_device_api():
     if not hasattr(android_device_api, "result"):
         assert configuration.lldb_platform_url is not None
@@ -97,6 +101,9 @@ def finalize_build_dictionary(dictionary):
             dictionary = {}
         dictionary["OS"] = "Android"
         dictionary["PIE"] = 1
+    elif target_is_remote_linux():
+        dictionary = dictionary or {}
+        dictionary["OS"] = "Linux"
     return dictionary
 
 

@@ -97,6 +101,9 @@ def finalize_build_dictionary(dictionary):
dictionary = {}
dictionary["OS"] = "Android"
dictionary["PIE"] = 1
elif target_is_remote_linux():
dictionary = dictionary or {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Pull the dictionary checking-logic out of these blocks and put it at the top of the function:

def finalize_build_dictionary(dictionary):
    if dictionary is None:
        dictionary = {}
    if target_is_android():
    # ...

@@ -97,6 +101,9 @@ def finalize_build_dictionary(dictionary):
dictionary = {}
dictionary["OS"] = "Android"
dictionary["PIE"] = 1
elif target_is_remote_linux():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, I think we should do this for all linux systems, not just remote ones. (Ideally, I would do it for all systems overall, but I can understand if you're reluctant to do that.)

You can use getPlatform to get the platform/os name for both local and remote runs.

Copy link

github-actions bot commented Jul 8, 2024

✅ With the latest revision this PR passed the Python code formatter.

Comment on lines 59 to 62
def target_is_remote_linux():
return configuration.lldb_platform_name == "remote-linux"


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this isn't used anymore.

"windows": "Windows_NT",
}
dictionary["OS"] = platform_name_to_uname[getPlatform()]
dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this under the else: branch? I would expect we need to set HOST_OS even if we're targetting android or darwin...

@dzhidzhoev dzhidzhoev force-pushed the lldb/target-os branch 3 times, most recently from d47f730 to b6e1aa2 Compare July 9, 2024 10:50
@dzhidzhoev
Copy link
Member Author

Thank you! Updated it: improved code for Darwin host detection, and removed overriding of HOST_OS in Makefile.

Comment on lines 133 to 136
# Triple is not available if we're not connected yet
if p.GetName() == "remote-linux":
return "linux"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why was this necessary? I get the connected part, but who was asking for the platform before connecting?

Copy link
Member Author

@dzhidzhoev dzhidzhoev Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be relevant if _get_platform_os is called before the connection is established, or, for example, if it has failed to be established. (I think I've caught an error a couple of times when the target went down during testing without that)
But yeah, currently I'm not aware of such use cases. Should it be removed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I would very much prefer that, as the code you added only handles linux. To support other oses, we would need to create a whole new mapping from lldb platform names to os strings. That list could then get out of sync, etc., so it would be best to just avoid doing that.

I'm not worried about the debug target going down during testing, as that means the test results will be meaningless anyway. If we find out we regularly need the os name before connecting, then I think we ought to revisit the mechanism for determining the OS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

…esting

Makefile.rules uses HOST_OS and OS variables for determining host and target
OSes for API tests compilation.

This commit starts moving the platform detection logic from Makefile to Python lldb
test suite.

When lldb's target is set to remote-linux, Makefile.rules script should be
executed with the target OS variable set to Linux.

This is useful for the case of Windows-to-Linux cross-testing.
Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@dzhidzhoev dzhidzhoev merged commit 7021e44 into llvm:main Jul 9, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants