xref: /PHP-7.1/ext/shmop/tests/001.phpt (revision 7af945e2)
1--TEST--
2shmop extension test
3--SKIPIF--
4<?php
5	if (!extension_loaded("shmop")) {
6		die("skip shmop() extension not available");
7	}
8?>
9--FILE--
10<?php
11	$hex_shm_id = 0xff3;
12	$write_d1 = "test #1 of the shmop() extension";
13	$write_d2 = "test #2 append data to shared memory segment";
14
15	echo "shm open for create: ";
16	$shm_id = shmop_open($hex_shm_id, "n", 0644, 1024);
17	if (!$shm_id) {
18		die("failed\n");
19	} else {
20		echo "ok\n";
21	}
22
23	echo "shm size is: " . ($shm_size = shmop_size($shm_id)) . "\n";
24
25	echo "shm write test #1: ";
26	$written = shmop_write($shm_id, $write_d1, 0);
27	if ($written != strlen($write_d1)) {
28		echo "failed\n";
29	} else {
30		echo "ok\n";
31	}
32
33	echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n";
34
35	shmop_close($shm_id);
36
37	echo "shm open for read only: ";
38	$shm_id = shmop_open($hex_shm_id, "a", 0644, 1024);
39	if (!$shm_id) {
40		echo "failed\n";
41	} else {
42		echo "ok\n";
43	}
44
45	echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n";
46
47	/* try to append data to the shared memory segment, this should fail */
48	@shmop_write($shm_id, $write_d1, $written);
49	echo $php_errormsg . "\n";
50
51	shmop_close($shm_id);
52
53	echo "shm open for read only: ";
54	$shm_id = shmop_open($hex_shm_id, "w", 0644, 1024);
55	if (!$shm_id) {
56		echo "failed\n";
57	} else {
58		echo "ok\n";
59	}
60
61	echo "shm write test #1: ";
62	$written = shmop_write($shm_id, $write_d2, $written);
63	if ($written != strlen($write_d2)) {
64		die("failed\n");
65	} else {
66		echo "ok\n";
67	}
68
69	echo "data in memory is: " . shmop_read($shm_id, 0, strlen($write_d1 . $write_d2)) . "\n";
70
71	echo "deletion of shm segment: ";
72	if (!shmop_delete($shm_id)) {
73		echo "failed\n";
74	} else {
75		echo "ok\n";
76	}
77
78	shmop_close($shm_id);
79?>
80--EXPECT--
81shm open for create: ok
82shm size is: 1024
83shm write test #1: ok
84data in memory is: test #1 of the shmop() extension
85shm open for read only: ok
86data in memory is: test #1 of the shmop() extension
87shmop_write(): trying to write to a read only segment
88shm open for read only: ok
89shm write test #1: ok
90data in memory is: test #1 of the shmop() extensiontest #2 append data to shared memory segment
91deletion of shm segment: ok
92