github.com/hpcng/singularity@v3.1.1+incompatible/docs/2.x-tests/30-actions.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2015-2016, Gregory M. Kurtzer. All rights reserved.
     4  #
     5  # "Singularity" Copyright (c) 2016, The Regents of the University of California,
     6  # through Lawrence Berkeley National Laboratory (subject to receipt of any
     7  # required approvals from the U.S. Dept. of Energy).  All rights reserved.
     8  #
     9  # This software is licensed under a customized 3-clause BSD license.  Please
    10  # consult LICENSE file distributed with the sources of this project regarding
    11  # your rights to use or distribute this software.
    12  #
    13  # NOTICE.  This Software was developed under funding from the U.S. Department of
    14  # Energy and the U.S. Government consequently retains certain rights. As such,
    15  # the U.S. Government has been granted for itself and others acting on its
    16  # behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software
    17  # to reproduce, distribute copies to the public, prepare derivative works, and
    18  # perform publicly and display publicly, and to permit other to do so.
    19  #
    20  #
    21  
    22  
    23  
    24  . ./functions
    25  
    26  test_init "Basic container action tests"
    27  
    28  
    29  
    30  CONTAINER="$SINGULARITY_TESTDIR/container.img"
    31  
    32  # Creating a new container
    33  stest 0 sudo singularity build "$CONTAINER" "../examples/busybox/Singularity"
    34  
    35  # Testing shell command
    36  stest 0 singularity shell "$CONTAINER" -c "true"
    37  stest 0 sh -c "echo true | singularity shell '$CONTAINER'"
    38  stest 1 singularity shell "$CONTAINER" -c "false"
    39  stest 1 sh -c "echo false | singularity shell '$CONTAINER'"
    40  
    41  # Testing exec command
    42  stest 0 singularity exec "$CONTAINER" true
    43  stest 0 singularity exec "$CONTAINER" /bin/true
    44  stest 1 singularity exec "$CONTAINER" false
    45  stest 1 singularity exec "$CONTAINER" /bin/false
    46  stest 1 singularity exec "$CONTAINER" /blahh
    47  stest 1 singularity exec "$CONTAINER" blahh
    48  stest 0 sh -c "echo hi | singularity exec $CONTAINER grep hi"
    49  stest 1 sh -c "echo bye | singularity exec $CONTAINER grep hi"
    50  
    51  
    52  # Testing run command
    53  stest 0 singularity run "$CONTAINER" true
    54  stest 1 singularity run "$CONTAINER" false
    55  
    56  
    57  # Testing run command properly hands arguments
    58  stest 0 sh -c "singularity run '$CONTAINER' foo | grep foo"
    59  
    60  
    61  # Testing singularity properly handles STDIN
    62  stest 0 sh -c "echo true | singularity shell '$CONTAINER'"
    63  stest 1 sh -c "echo false | singularity shell '$CONTAINER'"
    64  stest 0 sh -c "echo true | singularity exec '$CONTAINER' /bin/sh"
    65  stest 1 sh -c "echo false | singularity exec '$CONTAINER' /bin/sh"
    66  
    67  
    68  # Checking permissions
    69  stest 0 sh -c "singularity exec $CONTAINER id -u | grep `id -u`"
    70  stest 0 sh -c "sudo singularity exec $CONTAINER id -u | grep 0"
    71  
    72  
    73  test_cleanup
    74