guix-environment-container.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2015 David Thompson <davet@gnu.org>
  3. #
  4. # This file is part of GNU Guix.
  5. #
  6. # GNU Guix is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # GNU Guix is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Test 'guix environment'.
  20. #
  21. set -e
  22. guix environment --version
  23. if ! guile -c '((@@ (guix scripts environment) assert-container-features))'
  24. then
  25. # User containers are not supported; skip this test.
  26. exit 77
  27. fi
  28. tmpdir="t-guix-environment-$$"
  29. trap 'rm -r "$tmpdir"' EXIT
  30. mkdir "$tmpdir"
  31. # Make sure the exit value is preserved.
  32. if guix environment --container --ad-hoc --bootstrap guile-bootstrap \
  33. -- guile -c '(exit 42)'
  34. then
  35. false
  36. else
  37. test $? = 42
  38. fi
  39. # Make sure file-not-found errors in mounts are reported.
  40. if guix environment --container --ad-hoc --bootstrap guile-bootstrap \
  41. --expose=/does-not-exist -- guile -c 1 2> "$tmpdir/error"
  42. then
  43. false
  44. else
  45. grep "/does-not-exist" "$tmpdir/error"
  46. grep "[Nn]o such file" "$tmpdir/error"
  47. fi
  48. # Make sure that the right directories are mapped.
  49. mount_test_code="
  50. (use-modules (ice-9 rdelim)
  51. (ice-9 match)
  52. (srfi srfi-1))
  53. (define mappings
  54. (filter-map (lambda (line)
  55. (match (string-split line #\space)
  56. ;; Empty line.
  57. ((\"\") #f)
  58. ;; Ignore the root file system.
  59. ((_ \"/\" _ _ _ _)
  60. #f)
  61. ;; Ignore these types of file systems, except if they
  62. ;; correspond to a parent file system.
  63. ((_ mount (or \"tmpfs\" \"proc\" \"sysfs\" \"devtmpfs\"
  64. \"devpts\" \"cgroup\" \"mqueue\") _ _ _)
  65. (and (string-prefix? (getcwd) mount)
  66. mount))
  67. ((_ mount _ _ _ _)
  68. mount)))
  69. (string-split (call-with-input-file \"/proc/mounts\" read-string)
  70. #\newline)))
  71. (for-each (lambda (mount)
  72. (display mount)
  73. (newline))
  74. mappings)"
  75. guix environment --container --ad-hoc --bootstrap guile-bootstrap \
  76. -- guile -c "$mount_test_code" > $tmpdir/mounts
  77. cat "$tmpdir/mounts"
  78. test `wc -l < $tmpdir/mounts` -eq 4
  79. current_dir="`cd $PWD; pwd -P`"
  80. grep -e "$current_dir$" $tmpdir/mounts # current directory
  81. grep $(guix build guile-bootstrap) $tmpdir/mounts
  82. grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash
  83. rm $tmpdir/mounts
  84. abnormal_exit_code="
  85. (use-modules (system foreign))
  86. ;; Purposely make Guile crash with a segfault. :)
  87. (pointer->string (make-pointer 123) 123)"
  88. if guix environment --bootstrap --container \
  89. --ad-hoc guile-bootstrap -- guile -c "$abnormal_exit_code"
  90. then false;
  91. else
  92. test $? -gt 127
  93. fi