Debian Codegraph @

tests/platform.test

raw
1 # The file tests the tcl_platform variable and platform package.
2 #
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
6 #
7 # Copyright (c) 1999 Scriptics Corporation
8 #
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
12 package require tcltest 2.5
13 source [file join [file dirname [info script]] tcltests.tcl]
14
15 namespace eval ::tcl::test::platform {
16 namespace import ::tcltest::testConstraint
17 namespace import ::tcltest::test
18 namespace import ::tcltest::cleanupTests
19
20 # This is not how [variable] works. See TIP 276.
21 #variable ::tcl_platform
22 namespace upvar :: tcl_platform tcl_platform
23
24 ::tcltest::loadTestedCommands
25 catch [list package require -exact Tcltest [info patchlevel]]
26
27 testConstraint testCPUID [llength [info commands testcpuid]]
28
29 test platform-1.0 {tcl_platform(engine)} {
30 set tcl_platform(engine)
31 } {Tcl}
32
33 test platform-1.1 {TclpSetVariables: tcl_platform} {
34 interp create i
35 i eval {catch {unset tcl_platform(debug)}}
36 i eval {catch {unset tcl_platform(threaded)}}
37 set result [i eval {lsort [array names tcl_platform]}]
38 interp delete i
39 set result
40 } {byteOrder engine machine os osVersion pathSeparator platform pointerSize user wordSize}
41
42 # Test assumes twos-complement arithmetic, which is true of virtually
43 # everything these days. Note that this does *not* use wide(), and
44 # this is intentional since that could make Tcl's numbers wider than
45 # the machine-integer on some platforms...
46 test platform-2.1 {tcl_platform(wordSize) indicates size of native word} {
47 set result [expr {int(1 << (8 * $tcl_platform(wordSize) - 1))}]
48 # Result must be the largest bit in a machine word, which this checks
49 # without assuming how wide the word really is
50 list [expr {$result < 0}] [expr {$result ^ int($result - 1)}]
51 } {1 -1}
52
53 # On Windows/UNIX, test that the CPU ID works
54
55 test platform-3.1 {CPU ID on Windows/UNIX} \
56 -constraints testCPUID \
57 -body {
58 set cpudata [testcpuid 0]
59 binary format iii \
60 [lindex $cpudata 1] \
61 [lindex $cpudata 3] \
62 [lindex $cpudata 2]
63 } \
64 -match regexp \
65 -result {^(?:AuthenticAMD|CentaurHauls|CyrixInstead|GenuineIntel)$}
66
67 # The platform package makes very few promises, but does promise that the
68 # format of string it produces consists of two non-empty words separated by a
69 # hyphen.
70 package require platform
71 test platform-4.1 {format of platform::identify result} -constraints notValgrind -match regexp -body {
72 # [identify] may attempt to [exec] dpkg-architecture, which may not exist,
73 # in which case fork will not be followed by exec, and valgrind will issue
74 # "still reachable" reports.
75 platform::identify
76 } -result {^([^-]+-)+[^-]+$}
77 test platform-4.2 {format of platform::generic result} -match regexp -body {
78 platform::generic
79 } -result {^([^-]+-)+[^-]+$}
80
81 test platform-5.0 {format of platform::generic result} -setup {
82 set old_machine $::tcl_platform(machine)
83 set old_os $::tcl_platform(os)
84 set old_wordsize $::tcl_platform(wordSize)
85 set old_version $tcl_platform(osVersion)
86 set ::tcl_platform(machine) arm
87 set ::tcl_platform(os) Darwin
88 set ::tcl_platform(wordSize) 8
89 } -body {
90 set res {}
91 set l {macosx10.15-x86_64 macosx10.14-x86_64 macosx10.13-x86_64 macosx10.12-x86_64 macosx10.11-x86_64 macosx10.10-x86_64 macosx10.9-x86_64 macosx10.8-x86_64 macosx10.7-x86_64 macosx10.6-x86_64 macosx10.5-x86_64 macosx-arm macosx-x86_64 tcl}
92 foreach v {20.0 21.0 22.0 23.0 24.0 25.0 26.0} {
93 set ::tcl_platform(osVersion) $v
94 set id [platform::identify]
95 set l [linsert $l 0 [string range $id 0 end-4]-x86_64]
96 set l [linsert $l 0 $id]
97 lappend res $id
98 lappend res [expr {($l eq [platform::patterns $id]) ? 1 : [platform::patterns $id]}]
99 }
100 set res
101 } -cleanup {
102 set ::tcl_platform(machine) $old_machine
103 set ::tcl_platform(os) $old_os
104 set ::tcl_platform(wordSize) $old_wordsize
105 set ::tcl_platform(osVersion) $old_version
106 unset res l old_machine old_os old_wordsize old_version
107 } -result {macos11-arm 1 macos12-arm 1 macos13-arm 1 macos14-arm 1 macos15-arm 1 macos26-arm 1 macos27-arm 1}
108 test platform-5.1 {format of platform::patterns macos26-x86_64} -body {
109 platform::patterns macos26-x86_64
110 } -result {macos26-x86_64 macos15-x86_64 macos14-x86_64 macos13-x86_64 macos12-x86_64 macos11-x86_64 macosx10.15-x86_64 macosx10.14-x86_64 macosx10.14-i386-x86_64 macosx10.13-x86_64 macosx10.13-i386-x86_64 macosx10.12-x86_64 macosx10.12-i386-x86_64 macosx10.11-x86_64 macosx10.11-i386-x86_64 macosx10.10-x86_64 macosx10.10-i386-x86_64 macosx10.9-x86_64 macosx10.9-i386-x86_64 macosx10.8-x86_64 macosx10.8-i386-x86_64 macosx10.7-x86_64 macosx10.7-i386-x86_64 macosx10.6-x86_64 macosx10.6-i386-x86_64 macosx10.5-x86_64 macosx10.5-i386-x86_64 macosx-x86_64 macosx-i386-x86_64 tcl}
111 test platform-5.2 {format of platform::patterns macos26-arm} -body {
112 platform::patterns macos26-arm
113 } -result {macos26-arm macos26-x86_64 macos15-arm macos15-x86_64 macos14-arm macos14-x86_64 macos13-arm macos13-x86_64 macos12-arm macos12-x86_64 macos11-arm macos11-x86_64 macosx10.15-x86_64 macosx10.14-x86_64 macosx10.13-x86_64 macosx10.12-x86_64 macosx10.11-x86_64 macosx10.10-x86_64 macosx10.9-x86_64 macosx10.8-x86_64 macosx10.7-x86_64 macosx10.6-x86_64 macosx10.5-x86_64 macosx-arm macosx-x86_64 tcl}
114
115 # cleanup
116 cleanupTests
117
118 }
119 namespace delete ::tcl::test::platform
120 return
121
122 # Local Variables:
123 # mode: tcl
124 # End: