[110677] branches/gsoc13-tests/src/port1.0/tests
marius at macports.org
marius at macports.org
Tue Sep 3 07:24:33 PDT 2013
Revision: 110677
https://trac.macports.org/changeset/110677
Author: marius at macports.org
Date: 2013-09-03 07:24:33 -0700 (Tue, 03 Sep 2013)
Log Message:
-----------
port1.0: fixed portactivate and portdeactivate tests; added library.tcl containing worker_init
Modified Paths:
--------------
branches/gsoc13-tests/src/port1.0/tests/portactivate.test
Added Paths:
-----------
branches/gsoc13-tests/src/port1.0/tests/portdeactivate.test
Modified: branches/gsoc13-tests/src/port1.0/tests/portactivate.test
===================================================================
--- branches/gsoc13-tests/src/port1.0/tests/portactivate.test 2013-09-03 10:00:23 UTC (rev 110676)
+++ branches/gsoc13-tests/src/port1.0/tests/portactivate.test 2013-09-03 14:24:33 UTC (rev 110677)
@@ -4,7 +4,7 @@
set pwd [file normalize $argv0]
set pwd [eval file join {*}[lrange [file split $pwd] 0 end-1]]
-source ../../macports1.0/macports_fastload.tcl
+#source ../../macports1.0/macports_fastload.tcl
set portdbpath /opt/local/var/macports
package require macports 1.0
@@ -14,101 +14,19 @@
#set ui_options(ports_verbose) yes
mportinit ui_options
-##
-# This is basically a copy of macports::worker_init, but without using
-# sub-interpreters
-proc macports_worker_init {} {
- interp alias {} _cd {} cd
-
- proc PortSystem {version} {
- package require port $version
- }
-
- # Clearly separate slave interpreters and the master interpreter.
- interp alias {} mport_exec {} mportexec
- interp alias {} mport_open {} mportopen
- interp alias {} mport_close {} mportclose
- interp alias {} mport_lookup {} mportlookup
- interp alias {} mport_info {} mportinfo
-
- # Export some utility functions defined here.
- interp alias {} macports_create_thread {} macports::create_thread
- interp alias {} getportworkpath_from_buildpath {} macports::getportworkpath_from_buildpath
- interp alias {} getportresourcepath {} macports::getportresourcepath
- interp alias {} getportlogpath {} macports::getportlogpath
- interp alias {} getdefaultportresourcepath {} macports::getdefaultportresourcepath
- interp alias {} getprotocol {} macports::getprotocol
- interp alias {} getportdir {} macports::getportdir
- interp alias {} findBinary {} macports::findBinary
- interp alias {} binaryInPath {} macports::binaryInPath
-
- # New Registry/Receipts stuff
- interp alias {} registry_new {} registry::new_entry
- interp alias {} registry_open {} registry::open_entry
- interp alias {} registry_write {} registry::write_entry
- interp alias {} registry_prop_store {} registry::property_store
- interp alias {} registry_prop_retr {} registry::property_retrieve
- interp alias {} registry_exists {} registry::entry_exists
- interp alias {} registry_exists_for_name {} registry::entry_exists_for_name
- interp alias {} registry_activate {} portimage::activate
- interp alias {} registry_deactivate {} portimage::deactivate
- interp alias {} registry_deactivate_composite {} portimage::deactivate_composite
- interp alias {} registry_uninstall {} registry_uninstall::uninstall
- interp alias {} registry_register_deps {} registry::register_dependencies
- interp alias {} registry_fileinfo_for_index {} registry::fileinfo_for_index
- interp alias {} registry_fileinfo_for_file {} registry::fileinfo_for_file
- interp alias {} registry_bulk_register_files {} registry::register_bulk_files
- interp alias {} registry_active {} registry::active
- interp alias {} registry_file_registered {} registry::file_registered
- interp alias {} registry_port_registered {} registry::port_registered
- interp alias {} registry_list_depends {} registry::list_depends
-
- # deferred options processing.
- interp alias {} getoption {} macports::getoption
-
- # ping cache
- interp alias {} get_pingtime {} macports::get_pingtime
- interp alias {} set_pingtime {} macports::set_pingtime
-
- # archive_sites.conf handling
- interp alias {} get_archive_sites_conf_values {} macports::get_archive_sites_conf_values
-
- foreach opt $macports::portinterp_options {
- if {![info exists $opt]} {
- global macports::$opt
- }
- if {[info exists $opt]} {
- set system_options($opt) $opt
- set ::$opt $opt
- }
- }
-
- foreach opt $macports::portinterp_deferred_options {
- global macports::$opt
- # define the trace hook.
- proc trace_$opt {name1 name2 op} {
- trace remove variable ::$opt read ::trace_$opt
- global $opt
- set $opt [getoption $opt]
- }
- # next access will actually define the variable.
- trace add variable ::$opt read ::trace_$opt
- # define some value now
- set $opt "?"
- }
-}
-
+source ./library.tcl
macports_worker_init
package require port 1.0
package require registry 1.0
+
test activate_start {
Activate start unit test.
Requires root for setting euid.
} -constraints {
root
-} -body {
+} -setup {
# file writable $prefix is used to determine whether privilege escalation
# is needed, so set prefix to a directory unwritable for this user
set prefix /usr/bin
@@ -117,6 +35,7 @@
set euid 0
set egid 0
+} -body {
# drop privileges; the code won't attempt to elevate privileges without
# that
seteuid 333
@@ -140,9 +59,10 @@
root
} -setup {
set destpath $pwd/work/destroot
+ set portbuildpath $pwd
+ set portdbpath $pwd/dbpath
set portpath $pwd
- #file copy -force $pwd/Portfile /tmp/
set mport [mportopen file://.]
# set $version var
@@ -156,24 +76,33 @@
set macports::channels(msg) {}
set macports::channels(notice) {}
- #set res [portdeactivate::deactivate_main]
- #if {[catch {portdeactivate::deactivate_main}] != 0} {
- # return "FAIL: cannot deactivate port"
- #}
+ if {[$workername eval eval_targets install] != 0} {
+ return "FAIL: port install failed"
+ }
} -body {
- #puts [catch {portactivate::activate_main}]
+ if {[$workername eval eval_targets activate] != 0} {
+ return "FAIL: cannot activate port after install"
+ }
+ if {[$workername eval eval_targets deactivate] != 0} {
+ return "FAIL: cannot deactivate port"
+ }
+ if {[$workername eval eval_targets activate] != 0} {
+ return "FAIL: cannot activate port after deactivate"
+ }
+ return "Port activate successful."
} -cleanup {
- if {0 != [$workername eval eval_targets uninstall]} {
+ if {[$workername eval eval_targets uninstall] != 0} {
return "FAIL: uninstall failed"
}
- if {0 != [$workername eval eval_targets clean]} {
+ if {[$workername eval eval_targets clean] != 0} {
return "FAIL: clean failed"
}
array set macports::channels $oldchannels
mportclose $mport
-} -result 0
+} -result "Port activate successful."
-cleanupTests
+
+cleanupTests
\ No newline at end of file
Added: branches/gsoc13-tests/src/port1.0/tests/portdeactivate.test
===================================================================
--- branches/gsoc13-tests/src/port1.0/tests/portdeactivate.test (rev 0)
+++ branches/gsoc13-tests/src/port1.0/tests/portdeactivate.test 2013-09-03 14:24:33 UTC (rev 110677)
@@ -0,0 +1,104 @@
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file normalize $argv0]
+set pwd [eval file join {*}[lrange [file split $pwd] 0 end-1]]
+
+#source ../../macports1.0/macports_fastload.tcl
+set portdbpath /opt/local/var/macports
+
+package require macports 1.0
+array set ui_options {}
+#set ui_options(ports_debug) yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+source ./library.tcl
+macports_worker_init
+
+package require port 1.0
+package require registry 1.0
+
+
+test activate_start {
+ Deactivate start unit test.
+ Requires root for setting euid.
+} -constraints {
+ root
+} -setup {
+ # file writable $prefix is used to determine whether privilege escalation
+ # is needed, so set prefix to a directory unwritable for this user
+ set prefix /usr/bin
+
+ # elevateToRoot uses $euid and $egid as the IDs to set
+ set euid 0
+ set egid 0
+
+} -body {
+ # drop privileges; the code won't attempt to elevate privileges without
+ # that
+ seteuid 333
+ if {[catch {portdeactivate::deactivate_start args}] != 0} {
+ return "FAIL: couldn't elevate privileges"
+ }
+
+ # when uid == 0 and euid == 0, the code will not attempt to elevate
+ # privileges
+ seteuid 0
+ if {[catch {portdeactivate::deactivate_start args}] != 0} {
+ return "FAIL: couldn't elevate privileges"
+ }
+ return "Deactivate_start successful."
+} -result "Deactivate_start successful."
+
+
+test deactivate_main {
+ Deactivate main unit test.
+} -constraints {
+ root
+} -setup {
+ set destpath $pwd/work/destroot
+ set portbuildpath $pwd
+ set portdbpath $pwd/dbpath
+ set portpath $pwd
+
+ set mport [mportopen file://.]
+
+ # set $version var
+ set workername [ditem_key $mport workername]
+
+ # portinstall setup
+ interp alias {} _cd {} cd
+
+ # hide all output. Deactivate this for debugging!
+ set oldchannels [array get macports::channels]
+ set macports::channels(msg) {}
+ set macports::channels(notice) {}
+
+ if {[$workername eval eval_targets install] != 0} {
+ return "FAIL: port install failed"
+ }
+
+} -body {
+ if {[$workername eval eval_targets activate] != 0} {
+ return "FAIL: cannot activate port after install"
+ }
+ if {[$workername eval eval_targets deactivate] != 0} {
+ return "FAIL: cannot deactivate port after activate"
+ }
+ return "Port deactivate successful."
+
+} -cleanup {
+ if {[$workername eval eval_targets uninstall] != 0} {
+ return "FAIL: uninstall failed"
+ }
+ if {[$workername eval eval_targets clean] != 0} {
+ return "FAIL: clean failed"
+ }
+ array set macports::channels $oldchannels
+
+ mportclose $mport
+} -result "Port deactivate successful."
+
+
+cleanupTests
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20130903/5c4d5c4f/attachment-0001.html>
More information about the macports-changes
mailing list