tools/testing/selftests/efivarfs/efivarfs.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/efivarfs/efivarfs.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/efivarfs/efivarfs.sh
Extension
.sh
Size
7922 bytes
Lines
379
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

cleanup() {
               for f in ${p[@]}; do
                       rm -f ${f}
               done
               if [ -e $var ]; then
                       file_cleanup $var
               fi
       }
       trap cleanup exit

       waitstart() {
               cat ${p[$[$1+3]]} > /dev/null
       }

       waitpipe() {
               echo 1 > ${p[$[$1+3]]}
               cat ${p[$1]} > /dev/null
       }

       endjob() {
               echo 1 > ${p[$1]}
               wait -n %$1
       }
}

test_multiple_zero_size()
{
       ##
       # check for remove on last close, set up three threads all
       # holding the variable (one write and two reads) and then
       # close them sequentially (waiting for completion) and check
       # the state of the variable
       ##

       { waitpipe 1; echo 1; } > $var 2> /dev/null &
       waitstart 1
       # zero length file should exist
       [ -e $var ] || exit 1
       # second and third delayed close
       { waitpipe 2; } < $var &
       waitstart 2
       { waitpipe 3; } < $var &
       waitstart 3
       # close first fd
       endjob 1
       # var should only be deleted on last close
       [ -e $var ] || exit 1
       # close second fd
       endjob 2
       [ -e $var ] || exit 1
       # file should go on last close
       endjob 3
       [ ! -e $var ] || exit 1
}

test_multiple_create()
{
       ##
       # set multiple threads to access the variable but delay
       # the final write to check the close of 2 and 3.  The
       # final write should succeed in creating the variable
       ##
       { waitpipe 1; printf '\x07\x00\x00\x00\x54'; } > $var &
       waitstart 1
       [ -e $var -a ! -s $var ] || exit 1
       { waitpipe 2; } < $var &
       waitstart 2
       { waitpipe 3; } < $var &
       waitstart 3
       # close second and third fds

Annotation

Implementation Notes