mirror of
				https://git.proxmox.com/git/mirror_corosync
				synced 2025-11-03 23:40:06 +00:00 
			
		
		
		
	CTS: add an audit to check for leaking shared memory
Signed-off-by: Angus Salkeld <asalkeld@redhat.com> Reviewed-by: Steven Dake <sdake@redhat.com>
This commit is contained in:
		
							parent
							
								
									59397b3c0c
								
							
						
					
					
						commit
						d3f0a492d2
					
				@ -41,7 +41,7 @@ EXTRA_DIST		= syncv2.c
 | 
			
		||||
if INSTALL_TESTAGENTS
 | 
			
		||||
agentdir = $(datadir)/$(PACKAGE)/tests
 | 
			
		||||
bin_PROGRAMS = $(TEST_AGENTS)
 | 
			
		||||
dist_agent_SCRIPTS = mem_leak_test.sh net_breaker.sh confdb-dispatch-deadlock.sh
 | 
			
		||||
dist_agent_SCRIPTS = mem_leak_test.sh net_breaker.sh confdb-dispatch-deadlock.sh shm_leak_audit.sh
 | 
			
		||||
 | 
			
		||||
AM_CFLAGS		= -fPIC
 | 
			
		||||
SERVICE_LCRSO		= syncv2
 | 
			
		||||
@ -50,7 +50,7 @@ LCRSO			= $(SERVICE_LCRSO:%=service_%.lcrso)
 | 
			
		||||
LCRSO_OBJS		= $(SOURCES:%.c=%.o)
 | 
			
		||||
else
 | 
			
		||||
noinst_PROGRAMS = $(TEST_AGENTS)
 | 
			
		||||
noinst_SCRIPTS = mem_leak_test.sh net_breaker.sh confdb-dispatch-deadlock.sh
 | 
			
		||||
noinst_SCRIPTS = mem_leak_test.sh net_breaker.sh confdb-dispatch-deadlock.sh shm_leak_audit.sh
 | 
			
		||||
LCRSO =
 | 
			
		||||
LCRSO_OBJS =
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										47
									
								
								cts/agents/shm_leak_audit.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										47
									
								
								cts/agents/shm_leak_audit.sh
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,47 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/etc/init.d/corosync status >/dev/null
 | 
			
		||||
CS_STATUS=$?
 | 
			
		||||
 | 
			
		||||
if [ $CS_STATUS -eq 0 ]
 | 
			
		||||
then
 | 
			
		||||
	# corosync running
 | 
			
		||||
	active=$(corosync-objctl runtime.connections. | grep active | cut -d= -f2)
 | 
			
		||||
	if [ $active -lt 2 ]
 | 
			
		||||
	then
 | 
			
		||||
		FILES=$(ls /dev/shm/qb-*)
 | 
			
		||||
		for f in $FILES
 | 
			
		||||
		do
 | 
			
		||||
			echo $f
 | 
			
		||||
		done
 | 
			
		||||
	else
 | 
			
		||||
		pids=$(corosync-objctl runtime.connections. | grep client_pid | cut -d= -f2)
 | 
			
		||||
 | 
			
		||||
		FILES=$(ls /dev/shm/qb-*)
 | 
			
		||||
		for f in $FILES
 | 
			
		||||
		do
 | 
			
		||||
			found=0
 | 
			
		||||
			for p in $pids
 | 
			
		||||
			do
 | 
			
		||||
				if [[ "$f" =~ "$p" ]]
 | 
			
		||||
				then
 | 
			
		||||
					found=1
 | 
			
		||||
				fi
 | 
			
		||||
			done
 | 
			
		||||
			if [ $found -eq 0 ]
 | 
			
		||||
			then
 | 
			
		||||
				echo $f
 | 
			
		||||
			fi
 | 
			
		||||
		done	
 | 
			
		||||
	fi
 | 
			
		||||
else
 | 
			
		||||
	FILES=$(ls /dev/shm/qb-*)
 | 
			
		||||
	for f in $FILES
 | 
			
		||||
	do
 | 
			
		||||
		echo $f
 | 
			
		||||
	done
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
exit 0
 | 
			
		||||
 | 
			
		||||
@ -39,7 +39,6 @@ Copyright (c) 2010 Red Hat, Inc.
 | 
			
		||||
# THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 | 
			
		||||
import sys
 | 
			
		||||
from cts.CTSaudits import AuditList
 | 
			
		||||
from cts.CTSscenarios import *
 | 
			
		||||
from corotests import CoroTestList
 | 
			
		||||
from corosync import *
 | 
			
		||||
@ -274,7 +273,7 @@ if __name__ == '__main__':
 | 
			
		||||
 | 
			
		||||
    # Create the Cluster Manager object
 | 
			
		||||
    cm = Environment['CMclass'](Environment)
 | 
			
		||||
    Audits = AuditList(cm)
 | 
			
		||||
    Audits = CoroAuditList(cm)
 | 
			
		||||
        
 | 
			
		||||
    if Environment["ListTests"] == 1 :
 | 
			
		||||
        Tests = CoroTestList(cm, Audits)
 | 
			
		||||
 | 
			
		||||
@ -47,6 +47,8 @@ from cts.CTS import ClusterManager
 | 
			
		||||
from cts.CTSscenarios import ScenarioComponent
 | 
			
		||||
from cts.CTS import RemoteExec
 | 
			
		||||
from cts.CTSvars import CTSvars
 | 
			
		||||
from cts.CTSaudits import ClusterAudit
 | 
			
		||||
from cts.CTSaudits import LogAudit
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
###################################################################
 | 
			
		||||
@ -329,6 +331,28 @@ class corosync_needle(ClusterManager):
 | 
			
		||||
    def Components(self):    
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
class ShmLeakAudit(ClusterAudit):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, cm):
 | 
			
		||||
        self.CM = cm
 | 
			
		||||
 | 
			
		||||
    def name(self):
 | 
			
		||||
        return "ShmLeakAudit"
 | 
			
		||||
 | 
			
		||||
    def is_applicable(self):
 | 
			
		||||
        return 1
 | 
			
		||||
 | 
			
		||||
    def __call__(self):
 | 
			
		||||
        rc = 1
 | 
			
		||||
 | 
			
		||||
        for node in self.CM.Env["nodes"]:
 | 
			
		||||
            (res, lines) = self.CM.rsh(node, "/usr/share/corosync/tests/shm_leak_audit.sh", None)
 | 
			
		||||
            for line in lines:
 | 
			
		||||
                self.CM.log("%s leaked %s" % (node, line))
 | 
			
		||||
                rc = 0
 | 
			
		||||
 | 
			
		||||
        return rc
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
###################################################################
 | 
			
		||||
class TestAgentComponent(ScenarioComponent):
 | 
			
		||||
@ -488,6 +512,7 @@ class TestAgent(object):
 | 
			
		||||
        try:
 | 
			
		||||
            res = self.read ()
 | 
			
		||||
        except RuntimeError, msg:
 | 
			
		||||
            res = None
 | 
			
		||||
            self.env.log("send_recv_dynamic: %s(); error: %s" % (self.func_name, msg))
 | 
			
		||||
 | 
			
		||||
        return res
 | 
			
		||||
@ -633,3 +658,17 @@ class VoteQuorumTestAgent(TestAgent):
 | 
			
		||||
            self.init()
 | 
			
		||||
            self.used = False
 | 
			
		||||
 | 
			
		||||
AllAuditClasses = []
 | 
			
		||||
AllAuditClasses.append(LogAudit)
 | 
			
		||||
AllAuditClasses.append(ShmLeakAudit)
 | 
			
		||||
 | 
			
		||||
def CoroAuditList(cm):
 | 
			
		||||
    result = []
 | 
			
		||||
    for auditclass in AllAuditClasses:
 | 
			
		||||
        a = auditclass(cm)
 | 
			
		||||
        if a.is_applicable():
 | 
			
		||||
            result.append(a)
 | 
			
		||||
    return result
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user