A semiconductor device includes a state code register that stores a state code
representing a present internal state. A state transition logic unit is configured
to determine a state code for a next internal state to be transited in accordance
with a predetermined logic, based on a state code provided from the state code
register and an input command instructing transition to a required state, and to
set the determined state code into the state code register with synchronizing an
internal clock. An expected value register is configured to hold an internal state
to be detected, as an expected value code and a comparing unit compares the state
code set in the state code register by the state transition logic unit to the expected
value code in the expected value register and supplying an equal state signal when
they coincide.