biralavor / 42_minishell

minishell, a 42 school team project to rebuild a tiny bash, using C language. Build with @Thais-Malheiros
MIT License
3 stars 0 forks source link

feat valgrind actions for minishell_tester REDIRECTS #386

Closed biralavor closed 1 month ago

biralavor commented 1 month ago

I couldn't make a better result than this:

name: minishell tester >> valgrind_syntax

on:
  push:
    branches:
    - main
    - '**feature**'
    - '**feat**'
    - '**bugfix**'
    - '**fix**'
    - '**release**'
  pull_request:
    branches:
    - main
    - '**feature**'
    - '**feat**'
    - '**bugfix**'
    - '**fix**'
    - '**release**'

jobs:
  valgrind_syntax:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    defaults:
      run:
        working-directory: ./
    steps:
      - name: Starting Github Actions
        uses: actions/checkout@v4.1.4

      - name: Install Aptitude
        run: sudo apt-get install aptitude

      - name: Install Valgrind
        run: sudo aptitude install -y valgrind

      - name: Submodule Init
        run: git submodule init && git submodule update

      - name: Building Program with MiniShell Makefile
        run: make

      - name: Minishell_Tester Starting Up Simulation
        run: |
          cd minishell_tester
          chmod 000 ./test_files/invalid_permission
          mkdir outfiles mini_outfiles bash_outfiles
          cd ..

      - name: Run Valgrind Tests
        env:
          TEST_FILE: minishell_tester/syntax
        run: |
          echo "Running Valgrind tests..."
          valgrind --tool=memcheck --track-origins=yes --leak-check=full --suppressions=./readline.sup ./minishell
          while IFS= read -r line || [[ -n "$line" ]]; do
            echo "Testing: $line"
            # Redirect stdin to /dev/null
            echo "$line" > /dev/null
            # Run minishell with redirected stdin
            ./minishell
            echo "------------------------"

            # Check for memory leaks
            if grep -q "ERROR SUMMARY:" valgrind-out.txt; then
              echo "Memory leak detected!"
              exit 1
            fi

            # Send 'exit'
            echo "exit" > /dev/null
            ./minishell
            echo "------------------------"

            # Check again for memory leaks
            if grep -q "ERROR SUMMARY:" valgrind-out.txt; then
              echo "Memory leak detected after exit!"
              exit 1
            fi

            # Exit after processing each line
            exit 0
          done < $TEST_FILE

      - name: Minishell_Tester CleanUp
        run: |
            cd minishell_tester
            chmod 666 ./test_files/invalid_permission
            rm -rf outfiles mini_outfiles bash_outfiles
            cd ..

      - name: Upload Test Results
        uses: actions/upload-artifact@v4
        with:
          name: valgrind-results
          path: valgrind-out.txt
biralavor commented 1 month ago

The actions result didn 't achieve the main goal:


0s
Run echo "Running Valgrind tests..."
Running Valgrind tests...
==3068== Memcheck, a memory error detector
==3068== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3068== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==3068== Command: ./minishell
==3068== 
<<< Born Again (mini) SHell >>>$ exit
==3068== 
==3068== HEAP SUMMARY:
==3068==     in use at exit: 194,727 bytes in 211 blocks
==3068==   total heap usage: 994 allocs, 783 frees, 237,025 bytes allocated
==3068== 
==3068== LEAK SUMMARY:
==3068==    definitely lost: 0 bytes in 0 blocks
==3068==    indirectly lost: 0 bytes in 0 blocks
==3068==      possibly lost: 0 bytes in 0 blocks
==3068==    still reachable: 0 bytes in 0 blocks
==3068==         suppressed: 194,727 bytes in 211 blocks
==3068== 
==3068== For lists of detected and suppressed errors, rerun with: -s
==3068== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Testing: |
<<< Born Again (mini) SHell >>>$ | echo oi
 syntax error near unexpected token `|'
<<< Born Again (mini) SHell >>>$ | |
<<< Born Again (mini) SHell >>>$ | $
 syntax error near unexpected token `|'
 syntax error near unexpected token `|'
 syntax error near unexpected token `|'
 syntax error near unexpected token `newline'
 syntax error near unexpected token `newline'
 syntax error near unexpected token `>'
 syntax error near unexpected token `newline'
 syntax error near unexpected token `newline'
<<< Born Again (mini) SHell >>>$ | >
<<< Born Again (mini) SHell >>>$ >
<<< Born Again (mini) SHell >>>$ >>
<<< Born Again (mini) SHell >>>$ >>>
<<< Born Again (mini) SHell >>>$ <
<<< Born Again (mini) SHell >>>$ <<
<<< Born Again (mini) SHell >>>$ echo hi <
 syntax error near unexpected token `newline'
 syntax error near unexpected token `|'
 syntax error near unexpected token `newline'
 syntax error near unexpected token `>>'
 syntax error near unexpected token `|'
 syntax error near unexpected token `|'
<<< Born Again (mini) SHell >>>$ cat    <| ls
<<< Born Again (mini) SHell >>>$ echo hi | >
<<< Born Again (mini) SHell >>>$ echo hi | > >>
<<< Born Again (mini) SHell >>>$ echo hi | < |
<<< Born Again (mini) SHell >>>$ echo hi |   |
<<< Born Again (mini) SHell >>>$ echo hi |  "|"
|: command not found
<<< Born Again (mini) SHell >>>$ exit
------------------------
grep: valgrind-out.txt: No such file or directory
<<< Born Again (mini) SHell >>>$ exit
------------------------
grep: valgrind-out.txt: No such file or directory