- 
                Notifications
    You must be signed in to change notification settings 
- Fork 369
[tools] Fix tools/test and not for user-mode emulation #212
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
          
     Open
      
      
            iamlouk
  wants to merge
  6
  commits into
  llvm:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
iamlouk:lk/tools-for-emulation
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b74e2f1
              
                [tools] Disable tools/test under user-mode emulation
              
              
                iamlouk 6474814
              
                [tools/not] Basic support for user-mode emulation
              
              
                iamlouk b6645ef
              
                Review comments
              
              
                iamlouk 321227a
              
                Replace test_not.cpp by test_not.py so that it can be tested under em…
              
              
                iamlouk 6156870
              
                Add new not argument instead of different target
              
              
                iamlouk 9bc637e
              
                Address review comments
              
              
                iamlouk File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| //===- test_not.cpp - Test for enviroment variables in the not tool -------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|  | ||
| #include <cstdlib> | ||
| #include <iostream> | ||
| #include <sstream> | ||
|  | ||
| #ifdef _WIN32 | ||
| #define WIN32_LEAN_AND_MEAN | ||
| #define NOMINMAX | ||
| #include <windows.h> | ||
| #endif | ||
|  | ||
| #if defined(__unix__) || defined(__APPLE__) | ||
| #include <spawn.h> | ||
| #include <sys/wait.h> | ||
| #endif | ||
|  | ||
| int main(int argc, char *const *argv) { | ||
| ++argv; | ||
| --argc; | ||
| if (argc == 0) | ||
| return EXIT_FAILURE; | ||
|  | ||
| #ifdef _WIN32 | ||
| SetEnvironmentVariableA("SET_IN_PARENT", "something"); | ||
| #else | ||
| setenv("SET_IN_PARENT", "something", 0); | ||
| #endif | ||
|  | ||
| int result; | ||
|  | ||
| #if defined(__unix__) || defined(__APPLE__) | ||
| pid_t pid; | ||
| extern char **environ; | ||
| if (posix_spawn(&pid, argv[0], NULL, NULL, argv, environ)) | ||
| return EXIT_FAILURE; | ||
| if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1) | ||
| return EXIT_FAILURE; | ||
| #else | ||
| std::stringstream ss; | ||
| ss << argv[0]; | ||
| for (int i = 1; i < argc; ++i) | ||
| ss << " " << argv[i]; | ||
| std::string cmd = ss.str(); | ||
| result = std::system(cmd.c_str()); | ||
| #endif | ||
|  | ||
| int retcode = 0; | ||
| int signal = 0; | ||
|  | ||
| #ifdef _WIN32 | ||
| // Handle abort() in msvcrt -- It has exit code as 3. abort(), aka | ||
| // unreachable, should be recognized as a crash. However, some binaries use | ||
| // exit code 3 on non-crash failure paths, so only do this if we expect a | ||
| // crash. | ||
| if (errno) { | ||
| // If the command interpreter was not found, errno will be set and 0 will | ||
| // be returned. It is unlikely that this will happen in our use case, but | ||
| // check anyway. | ||
| retcode = 1; | ||
| signal = 1; | ||
| } else { | ||
| // On Windows, result is the exit code, except for the special case above. | ||
| retcode = result; | ||
| signal = 0; | ||
| } | ||
| #elif defined(WIFEXITED) && defined(WEXITSTATUS) && defined(WIFSIGNALED) && \ | ||
| defined(WTERMSIG) | ||
| // On POSIX systems and Solaris, result is a composite value of the exit code | ||
| // and, potentially, the signal that caused termination of the command. | ||
| if (WIFEXITED(result)) | ||
| retcode = WEXITSTATUS(result); | ||
| if (WIFSIGNALED(result)) | ||
| signal = WTERMSIG(result); | ||
| #else | ||
| #error "Unsupported system" | ||
| #endif | ||
|  | ||
| if (!signal && retcode == EXIT_SUCCESS) | ||
| return EXIT_SUCCESS; | ||
| return EXIT_FAILURE; | ||
| } | 
This file was deleted.
      
      Oops, something went wrong.
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit